Created
February 26, 2013 22:30
-
-
Save gtrak/5042933 to your computer and use it in GitHub Desktop.
Request-scoped compojure bindings, compatible with defroutes.
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
(defmacro wrap-request-binding | |
"Wraps the ring handler definition to provide request-scoped bindings | |
via symbol-capture on %." | |
[bindings handler-def] | |
`(fn [request#] | |
(let [~'% request# | |
~@bindings] | |
(~handler-def request#)))) | |
(defmacro request-binding-handlers | |
"Request-scoped bindings on multiple handlers with symbol capture of % to request. | |
Expands to single handler composing sub-handlers with compojure's routes function." | |
[bindings & handlers] | |
`(wrap-request-binding ~bindings (compojure/routes ~@handlers))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment