mirror of
https://github.com/tokio-rs/axum.git
synced 2024-11-23 07:39:25 +01:00
Mention middleware::from_fn
in axum’s docs (#670)
Fixes https://github.com/tokio-rs/axum/issues/667
This commit is contained in:
parent
de37a3e737
commit
9d62b5c060
1 changed files with 11 additions and 3 deletions
|
@ -107,13 +107,21 @@ 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::{
|
||||
response::Response,
|
||||
response::Response,
|
||||
Router,
|
||||
body::{Body, BoxBody},
|
||||
http::Request,
|
||||
|
|
Loading…
Reference in a new issue