Skip to content

Instantly share code, notes, and snippets.

@gtrak
Created February 26, 2013 22:30
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 gtrak/5042933 to your computer and use it in GitHub Desktop.
Save gtrak/5042933 to your computer and use it in GitHub Desktop.
Request-scoped compojure bindings, compatible with defroutes.
(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