Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

route.md: Add wildcard example code #2569

Merged
merged 2 commits into from
May 2, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion axum/src/docs/routing/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::new().route("/*key", get(handler));

async fn handler(Path(path): Path<String>) -> 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`.

Expand Down
Loading