mirror of
https://github.com/metosin/reitit.git
synced 2026-02-08 12:53:12 +00:00
parameters-middleware & interceptor
This commit is contained in:
parent
08349e61df
commit
57bcf2ab44
4 changed files with 37 additions and 0 deletions
|
|
@ -0,0 +1,16 @@
|
||||||
|
(ns reitit.http.interceptors.parameters
|
||||||
|
(:require [ring.middleware.params :as params]))
|
||||||
|
|
||||||
|
(defn parameters-interceptor
|
||||||
|
"Interceptor to parse urlencoded parameters from the query string and form
|
||||||
|
body (if the request is a url-encoded 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"
|
||||||
|
[]
|
||||||
|
{:name ::parameters
|
||||||
|
:enter (fn [ctx]
|
||||||
|
(let [request (:request ctx)]
|
||||||
|
(assoc ctx :request (params/params-request request))))})
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
(ns reitit.ring.middleware.parameters
|
||||||
|
(:require [ring.middleware.params :as params]))
|
||||||
|
|
||||||
|
(def parameters-middleware
|
||||||
|
"Middleware to parse urlencoded parameters from the query string and form
|
||||||
|
body (if the request is a url-encoded 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"
|
||||||
|
{:name ::parameters
|
||||||
|
:enter (fn [ctx]
|
||||||
|
(let [request (:request ctx)]
|
||||||
|
(assoc ctx :request (params/params-request request))))})
|
||||||
3
test/clj/reitit/http/interceptors/parameters_test.clj
Normal file
3
test/clj/reitit/http/interceptors/parameters_test.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
(ns reitit.http.interceptors.parameters-test)
|
||||||
|
|
||||||
|
;; TODO
|
||||||
3
test/clj/reitit/ring/middleware/parameters_test.clj
Normal file
3
test/clj/reitit/ring/middleware/parameters_test.clj
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
(ns reitit.ring.middleware.parameters-test)
|
||||||
|
|
||||||
|
;; TODO
|
||||||
Loading…
Reference in a new issue