Skip to content

Instantly share code, notes, and snippets.

@ricardo-rossi
Created April 18, 2017 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ricardo-rossi/0e51e871b8dba9016d435c0147b51190 to your computer and use it in GitHub Desktop.
Save ricardo-rossi/0e51e871b8dba9016d435c0147b51190 to your computer and use it in GitHub Desktop.
CLJS Routing
defresource contact [handlers]
:allowed-methods #{:delete :put}
:available-media-types #{"application/json"}
:handle-ok (fn [{{{id :id} :route-params routes :routes} :request}]
(assert (realized? handlers))
(html [:div [:h2 "Contact: " id]
[:a {:href (path-for routes (:contacts @handlers))} "Index"]])))
(defn make-handlers [database]
(let [p (promise)]
;; Deliver the promise so it doesn't escape this function.
@(deliver p {:contacts (contacts database p)
:contact (contact p)})))
(defn make-routes [handlers]
["/" [["contacts" (:contacts handlers)]
[["contact/" :id] (:contact handlers)]
]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment