[フレーム]
Last Updated: February 25, 2016
·
755
· 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)

AltStyle によって変換されたページ (->オリジナル) /