Skip to content

Parameter Middleware

weavejester edited this page Oct 19, 2010 · 3 revisions

URL-Encoded Parameters

The [[ring.middleware.params/wrap-params|http://mmcgrana.github.com/ring/middleware.params-api.html#ring.middleware.params/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})
Clone this wiki locally