Skip to content

Commit 2ffd39e

Browse files
committed
README
1 parent 830e5d8 commit 2ffd39e

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

README.md

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,21 @@ There is also `defapi` as a short form for the common case of defining routes wi
152152

153153
## Request & response formats
154154

155-
Middlewares (and other handlers) can publish their capabilities to consume & produce different wire-formats. This information is passed to `ring-swagger` and added to swagger-docs & is available in the swagger-ui.
155+
Middlewares (and other handlers) can publish their capabilities to consume & produce different wire-formats.
156+
This information is passed to `ring-swagger` and added to swagger-docs & is available in the swagger-ui.
156157

157-
One can add own format middlewares (XML, EDN etc.) and add expose their capabilities by adding the supported content-type into request under keys `[:meta :consumes]` and `[:meta :produces]` accordingly.
158+
The default middleware on Compojure-API includes [ring-middleware-format](https://github.com/ngrunwald/ring-middleware-format)
159+
which supports multiple formats. If the first element of `defapi` body is a map it will be used to pass parameters to
160+
`api-middleware`, e.g. the formats which should be enabled.
161+
162+
```clojure
163+
(defapi app
164+
{:formats [:transit-json :edn]}
165+
(context "/api" [] ...))
166+
```
167+
168+
One can add own format middlewares (XML etc.) and add expose their capabilities by adding the
169+
supported content-type into request under keys `[:meta :consumes]` and `[:meta :produces]` accordingly.
158170

159171
## Routes
160172

@@ -369,7 +381,10 @@ Key `:responses` takes a map of http-status-code -> model map, which translates
369381

370382
## Route-specific middlewares
371383

372-
Key `:middlewares` takes a vector of middlewares to be applied to the route. Note that the middlewares are wrapped around the route, so they don't see any restructured bindinds from within the route body and they **are applied before the actual route is being matched**.
384+
Key `:middlewares` takes a vector of middlewares to be applied to the route.
385+
Note that the middlewares don't see any restructured bindinds from within the route body.
386+
They are executed inside the route so you can safely edit request etc. and the changes
387+
won't leak to other routes in the same context.
373388

374389
```clojure
375390
(DELETE* "/user/:id" []

0 commit comments

Comments
 (0)