Clarify what handler::any and service::any accepts (#337)

They only accept standard HTTP methods and don't think we can fix that
without breaking changes.

Fixes https://github.com/tokio-rs/axum/issues/289
This commit is contained in:
David Pedersen
2021-09-19 08:28:15 +00:00
committed by GitHub
parent bb5bcab116
commit 2a683417d1
4 changed files with 27 additions and 6 deletions
+18 -3
View File
@@ -28,8 +28,7 @@ mod into_service;
pub use self::into_service::IntoService;
/// Route requests to the given handler regardless of the HTTP method of the
/// request.
/// Route requests with any standard HTTP method to the given handler.
///
/// # Example
///
@@ -41,12 +40,28 @@ pub use self::into_service::IntoService;
///
/// async fn handler() {}
///
/// // All requests to `/` will go to `handler` regardless of the HTTP method.
/// let app = Router::new().route("/", any(handler));
/// # async {
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
/// # };
/// ```
///
/// Note that this only accepts the standard HTTP methods. If you need to
/// support non-standard methods use [`Handler::into_service`]:
///
/// ```rust
/// use axum::{
/// handler::Handler,
/// Router,
/// };
///
/// async fn handler() {}
///
/// let app = Router::new().route("/", handler.into_service());
/// # async {
/// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
/// # };
/// ```
pub fn any<H, B, T>(handler: H) -> OnMethod<H, B, T, EmptyRouter>
where
H: Handler<B, T>,