Mention middleware::from_fn in axum’s docs (#670)

Fixes https://github.com/tokio-rs/axum/issues/667
This commit is contained in:
David Pedersen 2021-12-27 23:30:08 +01:00 committed by GitHub
parent de37a3e737
commit 9d62b5c060
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -107,9 +107,17 @@ Additionally axum provides [`extract::extractor_middleware()`] for converting
any extractor into a middleware. See [`extract::extractor_middleware()`] for
more details.
## Writing your own middleware
## Writing your own middleware with `axum_extra::middleware::from_fn`
You can also write you own middleware by implementing [`tower::Service`]:
The easiest way to write a custom middleware is using
[`axum_extra::middleware::from_fn`]. See that function for more details.
[`axum_extra::middleware::from_fn`]: https://docs.rs/axum-extra/0.1/axum_extra/middleware/middleware_fn/fn.from_fn.html
## Writing your own middleware with `tower::Service`
For maximum control (and a more low level API) you can write you own middleware
by implementing [`tower::Service`]:
```rust
use axum::{