clojurehttp-kit

Clojure http-kit: get query params as map?


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


Solution

  • 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})