I'm trying to pull a value out of the url query string however I can return what I believe is a map, however when i use the below code, it doesn't process it as expected. Can anyone advise how I access specific values in the returned querystring datastructure?
http://localhost:8080/remservice?foo=bar
(defroutes my-routes
(GET "/" [] (layout (home-view)))
(GET "/remservice*" {params :query-params} (str (:parameter params))))
You'll need to wrap your handler in
compojure.handler/api
orcompojure.handler/site
to add appropriate middleware to gain access to:query-params
. This used to happen automagically indefroutes
, but no longer does. Once you do that, the{params :query-params}
destructuring form will causeparams
to be bound to{"foo" "bar"}
when you hit/remservice
withfoo=bar
as the query string.(Or you could add in
wrap-params
etc. by hand -- these reside in variousring.middleware.*
namespaces; see the code ofcompojure.handler
(link to the relevant file in Compojure 1.0.1) for their names.)E.g.
If you now hit
http://localhost:8080/remservice?foo=bar
, you should see{"foo" "bar"}
-- the textual representation of your query string parsed into a Clojure map.