Fork me on GitHub
#reitit
<
2018-04-24
>
ikitommi04:04:35

@dimovich this should work:

ikitommi04:04:46

["/chsk" {:get ring-ajax-get-or-ws-handshake
          :post ring-ajax-post}]

ikitommi04:04:56

get’s expanded into:

["/chsk" {:get {:handler ring-ajax-get-or-ws-handshake}
          :post {:handler ring-ajax-post}}]

dimovich08:04:35

I've tried this, but the client is getting HTTP 500 error

ikitommi08:04:59

and the (otherwise) same code works with Compojure?

ikitommi08:04:35

if you have a sample repo with both Compojure & Reitit, I could try to investigate.

dimovich15:04:34

made a sample repo, and in the end found out that I need to add wrap-keyword-params too :]

grierson06:04:23

I’m using Ring ‘wrap-param’ , which creates a ‘:param’ key with all of all the parameters in one map. Is there a way to apply dataspec coercion to that key? So that I can just pass the param key into my handler without having to destruct the request via :body, :path, :query parameters keys?

ikitommi06:04:42

@grierson currently no. Personally I think it’s better to have explicit definitions where the parameters are coming from. If you have same parameter (e.g. :id) defined in multiple locations (query, body, form, header, path), which one is used with :params?

ikitommi06:04:19

That said, the parameter lookup could be made configurable via router options. currently it’s defined in https://github.com/metosin/reitit/blob/master/modules/reitit-core/src/reitit/coercion.cljc#L44-L49

ikitommi06:04:54

(or the :params could be added there)

ikitommi09:04:57

oh, about the :params. If there would be a separate Coercion for those, it would be double-coercion. Better would be to add a custom middleware that reads all the coerced params and injects those into [:parameters :params].

ikitommi09:04:01

Something like:

ikitommi09:04:32

(def inject-coerced-params-middleware
  {:name ::inject-coerced-params
   :wrap (fn [handler]
           (fn [request]
             (handler
               (assoc-in
                 request [:parameters :params]
                 (->> (:parameters request) 
                      vals 
                      (apply merge))))))})

dimovich15:04:56

@ikitommi yes this works

👍 4
dimovich15:04:19

@ikitommi thanks for your help.