From 9b82725b14ee778c697cc7ec408ca21609bb76b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Wed, 15 Nov 2023 09:35:38 +0100 Subject: [PATCH 1/2] explain that `Router::merge` only merges paths and fallback --- axum/src/docs/routing/merge.md | 7 ++++++- axum/src/routing/tests/merge.rs | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/axum/src/docs/routing/merge.md b/axum/src/docs/routing/merge.md index b88175130b..2b8e43f77d 100644 --- a/axum/src/docs/routing/merge.md +++ b/axum/src/docs/routing/merge.md @@ -1,4 +1,4 @@ -Merge two routers into one. +Merge the paths of two routers into a single [`Router`]. This is useful for breaking apps into smaller pieces and combining them into one. @@ -71,6 +71,11 @@ let app = Router::new() # let _: axum::Router = app; ``` +# Merging routers with fallbacks + +When combining [`Router`]s with this method, the [fallback](Router::fallback) is also merged. +However only one of the routers can have a fallback. + # Panics - If two routers that each have a [fallback](Router::fallback) are merged. This diff --git a/axum/src/routing/tests/merge.rs b/axum/src/routing/tests/merge.rs index cc65628999..44b0ce8df7 100644 --- a/axum/src/routing/tests/merge.rs +++ b/axum/src/routing/tests/merge.rs @@ -135,6 +135,8 @@ async fn layer_and_handle_error() { let res = client.get("/timeout").send().await; assert_eq!(res.status(), StatusCode::REQUEST_TIMEOUT); + let res = client.get("/foo").send().await; + assert_eq!(res.status(), StatusCode::OK); } #[crate::test] From 68765367216d1a82e6c44d4beba8c1b74d099c71 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Sat, 18 Nov 2023 13:26:42 +0100 Subject: [PATCH 2/2] Update axum/src/docs/routing/merge.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Emil Gardström --- axum/src/docs/routing/merge.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/axum/src/docs/routing/merge.md b/axum/src/docs/routing/merge.md index 2b8e43f77d..4036df6b0b 100644 --- a/axum/src/docs/routing/merge.md +++ b/axum/src/docs/routing/merge.md @@ -1,4 +1,4 @@ -Merge the paths of two routers into a single [`Router`]. +Merge the paths and fallbacks of two routers into a single [`Router`]. This is useful for breaking apps into smaller pieces and combining them into one.