diff --git a/axum/src/docs/routing/route.md b/axum/src/docs/routing/route.md index db4ca3a0..7d7cb245 100644 --- a/axum/src/docs/routing/route.md +++ b/axum/src/docs/routing/route.md @@ -52,6 +52,29 @@ Examples: Wildcard captures can also be extracted using [`Path`](crate::extract::Path). +# Accepting multiple methods + +To accept multiple methods for the same route you must add all handlers at the +same time: + +```rust +use axum::{Router, routing::{get, delete}, extract::Path}; + +let app = Router::new().route( + "/", + get(get_root).post(post_root).delete(delete_root), +); + +async fn get_root() {} + +async fn post_root() {} + +async fn delete_root() {} +# async { +# axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); +# }; +``` + # More examples ```rust diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 74eaf0be..49f33497 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -69,12 +69,13 @@ //! // our router //! let app = Router::new() //! .route("/", get(root)) -//! .route("/foo", get(foo)) +//! .route("/foo", get(get_foo).post(post_foo)) //! .route("/foo/bar", get(foo_bar)); //! //! // which calls one of these handlers //! async fn root() {} -//! async fn foo() {} +//! async fn get_foo() {} +//! async fn post_foo() {} //! async fn foo_bar() {} //! # async { //! # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();