Clojure http-kit: get query params as map?

835 views Asked by At

I have a server with an endpoint .../end2 which I send parameters to, such as:

.../end2?a=2&b=1

How do I get a map {:a 2 :b 1}? I thought (:params request) is the way to go but I get an empty map..

2

There are 2 answers

1
Josh On BEST ANSWER

Assuming you're using compojure, the params are not automatically bound to the request, and ring middleware must be applied to do this:

(defroutes app-routes
  (GET "/end2" request (str (:params request))))

(def app
  (-> app-routes
      ring.middleware.params/wrap-params))

(run-server #'app {:port 8888})
0
Mamun On

You need to add ring middle ware to parse params. You could check ring default

You don't have to worry about nested params or others.