From c57c2847b2a986adfa51271b419729c6c1f6cc28 Mon Sep 17 00:00:00 2001 From: Martin Nordholts Date: Thu, 2 May 2024 21:13:08 +0200 Subject: [PATCH] route.md: Add wildcard example code (#2569) Co-authored-by: David Pedersen Co-authored-by: Jonas Platte --- axum/src/docs/routing/route.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/axum/src/docs/routing/route.md b/axum/src/docs/routing/route.md index eefbb21b..fa55f4fa 100644 --- a/axum/src/docs/routing/route.md +++ b/axum/src/docs/routing/route.md @@ -56,7 +56,22 @@ Note that `/*key` doesn't match empty segments. Thus: - `/*key` doesn't match `/` but does match `/a`, `/a/`, etc. - `/x/*key` doesn't match `/x` or `/x/` but does match `/x/a`, `/x/a/`, etc. -Wildcard captures can also be extracted using [`Path`](crate::extract::Path). +Wildcard captures can also be extracted using [`Path`](crate::extract::Path): + +```rust +use axum::{ + Router, + routing::get, + extract::Path, +}; + +let app: Router = Router::new().route("/*key", get(handler)); + +async fn handler(Path(path): Path) -> String { + path +} +``` + Note that the leading slash is not included, i.e. for the route `/foo/*rest` and the path `/foo/bar/baz` the value of `rest` will be `bar/baz`.