mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-01 00:50:32 +01:00
More clearly document accepting multiple methods (#503)
Seen a few users ask about this and could be documented more clearly.
This commit is contained in:
parent
89db85d202
commit
6372f93cc5
2 changed files with 26 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue