0.2.3 permalink Arrow_down_16x16
  • (wrap-params handler & [opts])
Middleware to parse urlencoded parameters from the query string and form
body (if the request is a urlencoded form). Adds the following keys to
the request map:
:query-params - a map of parameters from the query string
:form-params - a map of parameters from the body
:params - a merged map of all types of parameter
Takes an optional configuration map. Recognized keys are:
:encoding - encoding to use for url-decoding. If not specified, uses
the request character encoding, or "UTF-8" if no request
character encoding is set.

1 Example top

  • ;; This example adds support for parameters to a Ring handler:
    
    (use 'ring.middleware.params
         'ring.adapter.jetty)
    
    (defn handler [{params :params}]
      {:status  200
       :headers {"Content-Type" "text/plain"}
       :body    (str "Hello " (params "name"))})
    
    (def app
      (wrap-params handler))
    
    user=> (run-jetty app {:port 8080})
    
    
    ;; If you run this, then visit  you will see a message saying "Hello Bob"
Log in to add / edit an example.

See Also top

Log in to add a see also.

Plus_12x12 Minus_12x12 Source ring/middleware/params.clj:54 top

(defn wrap-params
  "Middleware to parse urlencoded parameters from the query string and form
  body (if the request is a urlencoded form). Adds the following keys to
  the request map:
    :query-params - a map of parameters from the query string
    :form-params  - a map of parameters from the body
    :params       - a merged map of all types of parameter
  Takes an optional configuration map. Recognized keys are:
    :encoding - encoding to use for url-decoding. If not specified, uses
                the request character encoding, or \"UTF-8\" if no request
                character encoding is set."
  [handler & [opts]]
  (fn [request]
    (let [encoding (or (:encoding opts)
                       (:character-encoding request)
                       "UTF-8")
          request  (if (:form-params request)
                     request
                     (assoc-form-params request encoding))
          request  (if (:query-params request)
                     request
                     (assoc-query-params request encoding))]
      (handler request))))
Vars in ring.middleware.params/wrap-params: defn fn let
Used in 0 other vars

Comments top

No comments for wrap-params. Log in to add a comment.