mirror of
https://github.com/metosin/reitit.git
synced 2025-12-17 08:21:11 +00:00
doc: using middleware from registry at ring-handler level
This commit is contained in:
parent
d809291553
commit
2f22838820
1 changed files with 15 additions and 1 deletions
|
|
@ -52,6 +52,20 @@ Router creation fails fast if the registry doesn't contain the middleware:
|
||||||
;| :bonus | reitit.ring_test$wrap_bonus@59fddabb |
|
;| :bonus | reitit.ring_test$wrap_bonus@59fddabb |
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Middleware defined in the registry can also be used on the `ring-handler` level:
|
||||||
|
|
||||||
|
```clj
|
||||||
|
(def app
|
||||||
|
(ring/ring-handler
|
||||||
|
(ring/router
|
||||||
|
["/api"
|
||||||
|
["/bonus" {:get (fn [{:keys [bonus]}]
|
||||||
|
{:status 200, :body {:bonus bonus}})}]]
|
||||||
|
{::middleware/registry {:bonus wrap-bonus}})
|
||||||
|
nil
|
||||||
|
{:middleware [[:bonus 15]]}))
|
||||||
|
```
|
||||||
|
|
||||||
## When to use the registry?
|
## When to use the registry?
|
||||||
|
|
||||||
Middleware as Keywords helps to keep the routes (all but handlers) as literal data (i.e. data that evaluates to itself), enabling the routes to be persisted in external formats like EDN-files and databases. Duct is a good example, where the [middleware can be referenced from EDN-files](https://github.com/duct-framework/duct/wiki/Configuration). It should be easy to make Duct configuration a Middleware Registry in `reitit-ring`.
|
Middleware as Keywords helps to keep the routes (all but handlers) as literal data (i.e. data that evaluates to itself), enabling the routes to be persisted in external formats like EDN-files and databases. Duct is a good example, where the [middleware can be referenced from EDN-files](https://github.com/duct-framework/duct/wiki/Configuration). It should be easy to make Duct configuration a Middleware Registry in `reitit-ring`.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue