I want to create a handler function which takes two inputs. One is a parameter taken from the url /name, and second is a param from the query string /name?x=3
(def my-app (app
[page-name] (handler page-name)))
(defn handler
[{:keys [params]} page-name]
(let [x (params "x")]
(-> (page-templ page-name x) response constantly)))
The above fails because the handler is expecting 2 params, however I am only passing one.
How do I get hold of the request map, and pass it to the handler ?
The request map in the above case contains a param named x.
It is best if you could dispatch on the page name, like that:
Here functions index-page and serve-login return function of one argument.
req is the request that will contain all the url parameters in key/value map. To get parameter value do this:
So the full solution would look something like this:
EDIT: Don’t forget to wrap you application into (wrap-keyword-params) and (wrap-params), here’s how you can do it: