Skip to content

Instantly share code, notes, and snippets.

@davegolland
Last active August 29, 2015 13:57
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 davegolland/9719171 to your computer and use it in GitHub Desktop.
Save davegolland/9719171 to your computer and use it in GitHub Desktop.
fnhouse blogpost gists
{;; HTTP-related info
:path "/entries/"
:method :post
:description
"Add a new entry to the guestbook"
;; information about the HTTP request that the handler expects
:request
{:body Entry
;; our function does not expect any query-params or uri-args, but in general they are supported
:query-params {}
:uri-args {}}
:responses {200 [Entry]}
;; additional metadata about the Clojure implementation
:resources {:guestbook s/Any}
:source-map
{:line 23
:column 1
:file "guesthouse.clj"
:ns "guesthouse"
:name "entries$POST"}}
(defnk entries$POST
"Add a new entry to the guestbook"
{:responses {200 [Entry]}}
[[:request body :- Entry]
[:resources guestbook]]
(swap! guestbook conj body))
(defnk entries$POST
"Add a new entry to the guestbook"
{:responses {200 [Entry]}}
[[:request body :- Entry]
[:resources guestbook]]
(swap! guestbook conj body))
(def Entry
"A simple Schema for a guestbook entry"
{:name String
:age Long
:lang (s/enum :clj :cljs)})
(plumbing.fnk.pfnk/input-schema entries$POST)
{Keyword Any,
:resources {Keyword Any, :guestbook Any},
:request {Keyword Any,
:body {:name java.lang.String,
:age java.lang.Long,
:lang (enum :cljs :clj)}}}
{:name "John"
:age 31
:lang :clojure}
(-> ;; take your resources
resources
;; pass them into the slurped up handlers
((handlers/nss->handlers-fn {"guestbook" 'guesthouse.guestbook}))
;; compile the handlers into a router
routes/root-handler
;; run jetty
(jetty/run-jetty options))
{:name "John"
:age "31.0"
:lang "clojure"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment