Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider supporting defmulti as handler #650

Open
robert-stuttaford opened this issue Sep 18, 2023 · 0 comments
Open

Consider supporting defmulti as handler #650

robert-stuttaford opened this issue Sep 18, 2023 · 0 comments

Comments

@robert-stuttaford
Copy link

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)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant