2018-08-02 13:20:39 +00:00
# Default Middleware
```clj
2023-02-21 13:17:00 +00:00
[metosin/reitit-middleware "0.6.0"]
2018-08-02 13:20:39 +00:00
```
2021-07-27 16:33:17 +00:00
Any Ring middleware can be used with `reitit-ring` , but using data-driven middleware is preferred as they are easier to manage and in many cases yield better performance. `reitit-middleware` contains a set of common ring middleware, lifted into data-driven middleware.
2018-08-02 13:20:39 +00:00
2018-12-30 14:53:15 +00:00
* [Parameter Handling ](#parameters-handling )
* [Exception Handling ](#exception-handling )
* [Content Negotiation ](#content-negotiation )
* [Multipart Request Handling ](#multipart-request-handling )
2019-05-01 19:24:32 +00:00
* [Inspecting Middleware Chain ](#inspecting-middleware-chain )
2018-08-02 13:20:39 +00:00
2018-12-30 14:53:15 +00:00
## Parameters Handling
2018-09-07 20:46:26 +00:00
`reitit.ring.middleware.parameters/parameters-middleware` to capture query- and form-params. Wraps
`ring.middleware.params/wrap-params` .
2021-09-30 23:44:36 +00:00
**NOTE**: This middleware will be factored into two parts: a query-parameters middleware and a Muuntaja format responsible for the the `application/x-www-form-urlencoded` body format. cf. https://github.com/metosin/reitit/issues/134
2018-09-07 20:46:26 +00:00
2018-12-30 14:53:15 +00:00
## Exception Handling
2018-08-02 13:20:39 +00:00
2019-05-25 12:57:34 +00:00
See [Exception Handling with Ring ](exceptions.md ).
2018-08-02 13:20:39 +00:00
2020-06-02 14:45:26 +00:00
## Content Negotiation
See [Content Negotiation ](content_negotiation.md ).
2018-12-30 14:53:15 +00:00
## Multipart Request Handling
2018-08-02 13:20:39 +00:00
2018-08-22 17:06:09 +00:00
Wrapper for [Ring Multipart Middleware ](https://github.com/ring-clojure/ring/blob/master/ring-core/src/ring/middleware/multipart_params.clj ). Emits swagger `:consumes` definitions automatically.
Expected route data:
2021-07-27 16:33:17 +00:00
2018-08-22 17:06:09 +00:00
| key | description |
| -------------|-------------|
| `[:parameters :multipart]` | mounts only if defined for a route.
2018-08-02 13:20:39 +00:00
```clj
(require '[reitit.ring.middleware.multipart :as multipart])
```
2018-08-22 17:06:09 +00:00
* `multipart/multipart-middleware` a preconfigured middleware for multipart handling
* `multipart/create-multipart-middleware` to generate with custom configuration
2019-05-01 19:24:32 +00:00
## Inspecting Middleware Chain
2018-12-30 14:53:15 +00:00
2019-05-01 19:24:32 +00:00
`reitit.ring.middleware.dev/print-request-diffs` is a [middleware chain transforming function ](transforming_middleware_chain.md ). It prints a request and response diff between each middleware. To use it, add the following router option:
2018-12-30 14:53:15 +00:00
```clj
:reitit.middleware/transform reitit.ring.middleware.dev/print-request-diffs
```
Partial sample output:

2018-08-02 13:20:39 +00:00
## Example app
See an example app with the default middleware in action: https://github.com/metosin/reitit/blob/master/examples/ring-swagger/src/example/server.clj.