reitit
reitit copied to clipboard
Consider supporting defmulti as handler
We use defmulti
to dispatch API actions on a map key. To avoid needing to wrap that defmulti
in a normal function, so that it can be used as a Reitit ring handler, these two protocols need to be extended. In the sample code below, all I did was repeat the clojure.lang.Fn
implementation.
(extend-protocol reitit.core/Expand
clojure.lang.MultiFn
(expand [this _] {:handler this}))
(extend-protocol reitit.interceptor/IntoInterceptor
clojure.lang.MultiFn
(into-interceptor [this data opts]
(reitit.interceptor/into-interceptor
{:name :reitit.interceptor/handler
::handler this
:enter (fn [ctx]
(assoc ctx :response (this (:request ctx))))}
data opts)))