Skip to content

Instantly share code, notes, and snippets.

@gtrak
Last active December 13, 2015 17:28
Show Gist options
  • Save gtrak/4948166 to your computer and use it in GitHub Desktop.
Save gtrak/4948166 to your computer and use it in GitHub Desktop.
;;; helpful to get rid of repetitive compojure destructuring.
(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 req#))))
(defmacro binding-handlers
"Request-scoped bindings on multiple handlers. Expands to a sequence of
handlers (use routes instead of defroutes)."
[bindings & handlers]
(mapv (fn [handler] `(wrap-request-binding ~bindings ~handler)) handlers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment