1

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..

shakedzy
  • 2,853
  • 5
  • 32
  • 62

2 Answers2

3

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})
Josh
  • 4,726
  • 2
  • 20
  • 32
  • Worth to note, for those learning Clojure like me, that REQUIRING things is super important, otherwise you'll spend half an hour debugging why the SO solution does not work XD – MVCDS Apr 11 '19 at 16:14
-1

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.

Mamun
  • 512
  • 3
  • 10