clojurepedestal

How to get the URL query params in Pedestal?


How do I get the URL params into the request map in Pedestal? I am assuming that this needs the use of an interceptor? However the Pedestal documentation (or severe lack thereof) does not make this at all clear. Thanks.


Solution

  • Query parameters are parsed automatically by Pedestal, and the resulting map is placed in the request map under the :query-params key.

    As a simple example, start with the pedestal-service template and use the following definitions:

    (defn home-page
      [request]
      (ring-resp/response (format "Hello with params: %s" (:query-params request))))
    
    (defroutes routes
      [[["/" {:get home-page}]]])
    

    Now if you browse to http://localhost:8080/?param=true&other=1234, you should see Hello world with paramters: {:param "true", :other "1234"}.