Add RouteDsl::or to combine routes (#108)

With this you'll be able to do:

```rust
let one = route("/foo", get(|| async { "foo" }))
    .route("/bar", get(|| async { "bar" }));

let two = route("/baz", get(|| async { "baz" }));

let app = one.or(two);
```

Fixes https://github.com/tokio-rs/axum/issues/101
This commit is contained in:
David Pedersen
2021-08-07 17:09:45 +02:00
committed by GitHub
parent b1e7a6ae7b
commit 045ec57d92
6 changed files with 385 additions and 2 deletions
+3
View File
@@ -125,6 +125,8 @@
//! Routes can also be dynamic like `/users/:id`. See [extractors](#extractors)
//! for more details.
//!
//! You can also define routes separately and merge them with [`RoutingDsl::or`].
//!
//! ## Precedence
//!
//! Note that routes are matched _bottom to top_ so routes that should have
@@ -662,6 +664,7 @@
//! [`IntoResponse`]: crate::response::IntoResponse
//! [`Timeout`]: tower::timeout::Timeout
//! [examples]: https://github.com/tokio-rs/axum/tree/main/examples
//! [`RoutingDsl::or`]: crate::routing::RoutingDsl::or
//! [`axum::Server`]: hyper::server::Server
#![warn(