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
@@ -1,3 +1,5 @@
#![allow(clippy::blacklisted_name)]
use crate::{
extract::RequestParts, handler::on, prelude::*, routing::nest, routing::MethodFilter, service,
};
@@ -18,6 +20,7 @@ use tower::{make::Shared, service_fn, BoxError, Service, ServiceBuilder};
use tower_http::{compression::CompressionLayer, trace::TraceLayer};
mod nest;
mod or;
#[tokio::test]
async fn hello_world() {