mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-24 00:00:16 +02:00
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:
+18
-3
@@ -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>,
|
||||
|
||||
Reference in New Issue
Block a user