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:
David Pedersen 2021-11-13 20:00:04 +01:00 committed by GitHub
parent 89db85d202
commit 6372f93cc5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 2 deletions

View file

@ -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

View file

@ -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();