Fallback to calling next route if no methods match (#224)

This removes a small foot gun from the routing.

This means matching different HTTP methods for the same route that
aren't defined together now works.

So `Router::new().route("/", get(...)).route("/", post(...))` now
accepts both `GET` and `POST`. Previously only `POST` would be accepted.
This commit is contained in:
David Pedersen
2021-08-21 01:00:12 +02:00
committed by GitHub
parent 971c0a394a
commit 0d8f8b7b6c
6 changed files with 112 additions and 94 deletions
-24
View File
@@ -203,30 +203,6 @@
//! # }
//! ```
//!
//! ## Matching multiple methods
//!
//! If you want a path to accept multiple HTTP methods you must add them all at
//! once:
//!
//! ```rust,no_run
//! use axum::{
//! Router,
//! handler::{get, post},
//! };
//!
//! // `GET /` and `POST /` are both accepted
//! let app = Router::new().route("/", get(handler).post(handler));
//!
//! // This will _not_ work. Only `POST /` will be accessible.
//! let wont_work = Router::new().route("/", get(handler)).route("/", post(handler));
//!
//! async fn handler() {}
//! # async {
//! # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap();
//! # axum::Server::bind(&"".parse().unwrap()).serve(wont_work.into_make_service()).await.unwrap();
//! # };
//! ```
//!
//! ## Routing to any [`Service`]
//!
//! axum also supports routing to general [`Service`]s: