better docs

This commit is contained in:
Tommi Reiman 2018-08-22 19:39:04 +03:00
parent c11d21d9ec
commit 7cc8f84297
2 changed files with 44 additions and 2 deletions

View file

@ -109,12 +109,14 @@
(-> options wrap handler)))
(def exception-middleware
"A preconfigured exception handling Middleware. To configure the exceptions handlers, use
`create-exception-handler` instead."
{:name ::exception
:spec ::spec
:wrap (wrap default-handlers)})
(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
the exception handler for the thown/raised exception identifier. Exception
idenfier is either a `Keyword` or a Exception Class.

View file

@ -9,6 +9,21 @@
(defn- displace [x] (with-meta x {:displace true}))
(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
:spec ::spec
:compile (fn [{:keys [muuntaja]} _]
@ -18,6 +33,15 @@
:wrap #(muuntaja.middleware/wrap-format % muuntaja)}))})
(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
:spec ::spec
:compile (fn [{:keys [muuntaja]} _]
@ -25,14 +49,30 @@
{:wrap #(muuntaja.middleware/wrap-format-negotiate % muuntaja)}))})
(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
:spec ::spec
:compile (fn [{:keys [muuntaja]} _]
(if muuntaja
{:data {:swagger {:consumes (displace (m/decodes muuntaja))}}
:wrap #(muuntaja.middleware/wrap-format-request % muuntaja)}))})
©
(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
:spec ::spec
:compile (fn [{:keys [muuntaja]} _]