From f7a0011ea55d448833bcec262311aa87152d51ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emil=20Gardstr=C3=B6m?= Date: Sat, 18 Nov 2023 13:36:25 +0100 Subject: [PATCH] explain that `Router::merge` only merges paths and fallback (#2316) Co-authored-by: David Pedersen --- 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 b8817513..4036df6b 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 and fallbacks 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 cc656289..44b0ce8d 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]