Fork me on GitHub
#reitit
<
2022-10-12
>
zach23:10:53

Hello! Is the reitit parameters-middleware supposed to convert the parameters into keywords? If not, is there an additional middleware to add to the stack to do this action? I am trying to really learn how reitit and ring work as i build up a custom web server, but am getting a little lost in the middleware stack. My app, looks, essentially, like so:

(def routes
  [
   ["/" {:get (fn [req] (home req))}]
   ["/login" {:post (fn [req] (login req))}]
   ])

(def app
  (ring/ring-handler
   (ring/router routes
    {:data {:muuntaja m/instance
            :middleware [parameters/parameters-middleware
                         format-negotiate-middleware
                         hc/wrap-response-middleware
                         format-response-middleware
                         exception-middleware
                         format-request-middleware]}})
   (ring/routes
    (ring/create-resource-handler {:path "/"})
    (ring/redirect-trailing-slash-handler)
    (ring/create-default-handler
     {:not-found (constantly {:status 404
                              :body "<h1>Route not found</h1>"})}))))
When the routes have query-params or form-params, they are included in the request in the appropriate :query-params and :form-params maps, but as strings. Is there a way to have them be keyword maps? I tried to add the ring middleware wrap-keyword-params but it didn’t seem to change the behaviour. /login?test=foo adds {:query-params {"test" "foo"}} to the request map

wevrem01:10:14

At least in my project, as far as I can tell keywordizing of query params is done on the backend by ring/ring-defaults, and on the frontend by reitit.coercion.schema/coercion.

wevrem01:10:31

At least that is the way I’ve set it up. Probably other ways to do it.

zach22:10:58

thank you!