Skip to content

Instantly share code, notes, and snippets.



Last active Dec 10, 2015
What would you like to do?
Get Rails like controller syntax from Compojure DSL in 5 minutes with few very simple macros.
(defroutes posts-routes
(context "/posts" []
(GET "/" request ...)
(GET "/new" request ...)
(POST "/" request ...)))
(defmacro defcontroller
([nm & exprs]
`(defroutes ~(symbol (str (name nm) "-routes"))
(context ~(str "/" (name nm)) []
(defmacro index [bindings & exprs]
`(GET "/" ~bindings ~@exprs))
(defmacro new [bindings & exprs]
`(GET "/new" ~bindings ~@exprs))
(defmacro create [bindings & exprs]
`(POST "/" ~bindings ~@exprs))
(defcontroller posts
(index request ...)
(new request ...)
(create request ...))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment