Skip to content

Commit

Permalink
route.md: Add wildcard example code
Browse files Browse the repository at this point in the history
To developers completely new to axum, it helps a lot to give example
code on to get access to the variable path in a handler.
  • Loading branch information
Enselic committed Feb 6, 2024
1 parent 5f7fcc5 commit 6697417
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions axum/src/docs/routing/route.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ Wildcard captures can also be extracted using [`Path`](crate::extract::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`.

Example:

```rust
let app = Router::new().route("/*key", get(handler));

async fn handler(path: axum::extract::Path<String>) -> String {
path.0
}
```

# Accepting multiple methods

To accept multiple methods for the same route you can add all handlers at the
Expand Down

0 comments on commit 6697417

Please sign in to comment.