From 9d62b5c06080b57aa8af86b88dbb16ac317c4789 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Mon, 27 Dec 2021 23:30:08 +0100 Subject: [PATCH] =?UTF-8?q?Mention=20`middleware::from=5Ffn`=20in=20axum?= =?UTF-8?q?=E2=80=99s=20docs=20(#670)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes https://github.com/tokio-rs/axum/issues/667 --- axum/src/docs/middleware.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/axum/src/docs/middleware.md b/axum/src/docs/middleware.md index 5592dc0f..b35bffa1 100644 --- a/axum/src/docs/middleware.md +++ b/axum/src/docs/middleware.md @@ -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,