mirror of
https://github.com/metosin/reitit.git
synced 2026-01-28 17:00:34 +00:00
better docs
This commit is contained in:
parent
c11d21d9ec
commit
7cc8f84297
2 changed files with 44 additions and 2 deletions
|
|
@ -109,12 +109,14 @@
|
||||||
(-> options wrap handler)))
|
(-> options wrap handler)))
|
||||||
|
|
||||||
(def exception-middleware
|
(def exception-middleware
|
||||||
|
"A preconfigured exception handling Middleware. To configure the exceptions handlers, use
|
||||||
|
`create-exception-handler` instead."
|
||||||
{:name ::exception
|
{:name ::exception
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:wrap (wrap default-handlers)})
|
:wrap (wrap default-handlers)})
|
||||||
|
|
||||||
(defn create-exception-middleware
|
(defn create-exception-middleware
|
||||||
"Creates a reitit middleware that catches all exceptions. Takes a map
|
"Creates a Middleware that catches all exceptions. Takes a map
|
||||||
of `identifier => exception request => response` that is used to select
|
of `identifier => exception request => response` that is used to select
|
||||||
the exception handler for the thown/raised exception identifier. Exception
|
the exception handler for the thown/raised exception identifier. Exception
|
||||||
idenfier is either a `Keyword` or a Exception Class.
|
idenfier is either a `Keyword` or a Exception Class.
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,21 @@
|
||||||
(defn- displace [x] (with-meta x {:displace true}))
|
(defn- displace [x] (with-meta x {:displace true}))
|
||||||
|
|
||||||
(def format-middleware
|
(def format-middleware
|
||||||
|
"Middleware for content-negotiation, request and response formatting.
|
||||||
|
|
||||||
|
Negotiates a request body based on `Content-Type` header and response body based on
|
||||||
|
`Accept`, `Accept-Charset` headers. Publishes the negotiation results as `:muuntaja/request`
|
||||||
|
and `:muuntaja/response` keys into the request.
|
||||||
|
|
||||||
|
Decodes the request body into `:body-params` using the `:muuntaja/request` key in request
|
||||||
|
if the `:body-params` doesn't already exist.
|
||||||
|
|
||||||
|
Encodes the response body using the `:muuntaja/response` key in request if the response
|
||||||
|
doesn't have `Content-Type` header already set.
|
||||||
|
|
||||||
|
| key | description |
|
||||||
|
| -------------|-------------|
|
||||||
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format
|
{:name ::format
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja]} _]
|
||||||
|
|
@ -18,6 +33,15 @@
|
||||||
:wrap #(muuntaja.middleware/wrap-format % muuntaja)}))})
|
:wrap #(muuntaja.middleware/wrap-format % muuntaja)}))})
|
||||||
|
|
||||||
(def format-negotiate-middleware
|
(def format-negotiate-middleware
|
||||||
|
"Middleware for content-negotiation.
|
||||||
|
|
||||||
|
Negotiates a request body based on `Content-Type` header and response body based on
|
||||||
|
`Accept`, `Accept-Charset` headers. Publishes the negotiation results as `:muuntaja/request`
|
||||||
|
and `:muuntaja/response` keys into the request.
|
||||||
|
|
||||||
|
| key | description |
|
||||||
|
| -------------|-------------|
|
||||||
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format-negotiate
|
{:name ::format-negotiate
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja]} _]
|
||||||
|
|
@ -25,14 +49,30 @@
|
||||||
{:wrap #(muuntaja.middleware/wrap-format-negotiate % muuntaja)}))})
|
{:wrap #(muuntaja.middleware/wrap-format-negotiate % muuntaja)}))})
|
||||||
|
|
||||||
(def format-request-middleware
|
(def format-request-middleware
|
||||||
|
"Middleware for request formatting.
|
||||||
|
|
||||||
|
Decodes the request body into `:body-params` using the `:muuntaja/request` key in request
|
||||||
|
if the `:body-params` doesn't already exist.
|
||||||
|
|
||||||
|
| key | description |
|
||||||
|
| -------------|-------------|
|
||||||
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format-request
|
{:name ::format-request
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja]} _]
|
||||||
(if muuntaja
|
(if muuntaja
|
||||||
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}
|
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}
|
||||||
:wrap #(muuntaja.middleware/wrap-format-request % muuntaja)}))})
|
:wrap #(muuntaja.middleware/wrap-format-request % muuntaja)}))})
|
||||||
|
©
|
||||||
(def format-response-middleware
|
(def format-response-middleware
|
||||||
|
"Middleware for response formatting.
|
||||||
|
|
||||||
|
Encodes the response body using the `:muuntaja/response` key in request if the response
|
||||||
|
doesn't have `Content-Type` header already set.
|
||||||
|
|
||||||
|
| key | description |
|
||||||
|
| -------------|-------------|
|
||||||
|
| `:muuntaja` | `muuntaja.core/Muuntaja` instance, does not mount if not set."
|
||||||
{:name ::format-response
|
{:name ::format-response
|
||||||
:spec ::spec
|
:spec ::spec
|
||||||
:compile (fn [{:keys [muuntaja]} _]
|
:compile (fn [{:keys [muuntaja]} _]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue