Last active
August 29, 2015 13:57
-
-
Save davegolland/9719171 to your computer and use it in GitHub Desktop.
fnhouse blogpost gists
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{;; 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"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defnk entries$POST | |
"Add a new entry to the guestbook" | |
{:responses {200 [Entry]}} | |
[[:request body :- Entry] | |
[:resources guestbook]] | |
(swap! guestbook conj body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defnk entries$POST | |
"Add a new entry to the guestbook" | |
{:responses {200 [Entry]}} | |
[[:request body :- Entry] | |
[:resources guestbook]] | |
(swap! guestbook conj body)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(def Entry | |
"A simple Schema for a guestbook entry" | |
{:name String | |
:age Long | |
:lang (s/enum :clj :cljs)}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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)}}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{:name "John" | |
:age 31 | |
:lang :clojure} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(-> ;; 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)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{: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