Last Updated: February 25, 2016
·
896
· killme2008

A macro to define handler for compojure

A macro to define handler for compojure that match parameters automatically.

(defmacro defhandler
  [name args & body]
  `(defn ~name [req#]
     (let [{:keys ~args :or {~'req req#}} (:params req#)]
       ~@body)))

Then use it define the handler and routes:

(defhandler signup [username password]
      ....)

(defroutes app-routes
  (POST "/signup" [] signup)

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

The website is part of the attack surface, not only the API behind it. Every script, iframe, and tag on a public page is code that did not go through the same review as the backend.

Security insights from Cside