Replace route with Router::new().route() (#215)

This way there is now only one way to create a router:

```rust
use axum::{Router, handler::get};

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

`nest` was changed in the same way:

```rust
use axum::Router;

let app = Router::new().nest("/foo", service);
```
This commit is contained in:
David Pedersen
2021-08-19 22:37:48 +02:00
committed by GitHub
parent 97b53768ba
commit ca4d9a2bb9
49 changed files with 652 additions and 625 deletions
+3 -2
View File
@@ -37,7 +37,7 @@ use tower::{BoxError, Layer, Service};
/// use axum::{
/// extract::{extractor_middleware, FromRequest, RequestParts},
/// handler::{get, post},
/// route,
/// Router,
/// };
/// use http::StatusCode;
/// use async_trait::async_trait;
@@ -76,7 +76,8 @@ use tower::{BoxError, Layer, Service};
/// // If we get here the request has been authorized
/// }
///
/// let app = route("/", get(handler))
/// let app = Router::new()
/// .route("/", get(handler))
/// .route("/foo", post(other_handler))
/// // The extractor will run before all routes
/// .layer(extractor_middleware::<RequireAuth>());