Skip to content

Instantly share code, notes, and snippets.

@jcromartie
Created January 19, 2010 15:47
Show Gist options
  • Save jcromartie/281015 to your computer and use it in GitHub Desktop.
Save jcromartie/281015 to your computer and use it in GitHub Desktop.
(defn with-json [handler]
(fn [request]
(json/encode-to-str (handler request))))
(defn with-requires-https [handler]
(fn [request]
(if (= :https (:scheme request))
(handler request)
"No way José")))
(defn with-requires-authentication [handler]
(fn [request]
(let [id (-> request :route-params :id)
pw (-> request :params :password)]
(if (access/authenticate id pw)
(handler request)
"No way José"))))
(defroutes signup-api
; create an account
(POST "/accounts/" (decorate account-create (with-json)))
; get account info
(GET "/accounts/:id/" (decorate account-info (with-json)))
; update account info
(POST "/accounts/:id/" (decorate account-update
(with-requires-authentication)
(with-json)))
(ANY "/*" four-oh-four))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment