forked from ring-clojure/ring
-
Notifications
You must be signed in to change notification settings - Fork 1
Parameter Middleware
Ivo Wever edited this page May 2, 2015
·
5 revisions
The wrap-params middleware function adds support for url-encoded parameters.
Parameters in the HTTP body and URL query string are parsed into Clojure maps. The keys and values in the map are strings. For example:
"foo=bar" => {"foo" "bar"}
If the same parameter name occurs more than once, the values are placed in order into a vector:
"foo=bar&foo=baz" => {"foo" ["bar" "baz"]}
The parsed parameter maps are added to the following keys in the request map:
-
:query-params
- parameters parsed from the URL query string -
:form-params
- parameters parsed from the HTTP body -
:params
- A merged map of all parameter types
An example of use:
(ns example.params
(:use ring.middleware.params
ring.util.response
ring.adapter.jetty))
(defn handler [{params :params}]
(response (str "Hello " (params "name"))))
(run-jetty (wrap-params handler)
{:port 8080})