mirror of
https://github.com/tokio-rs/axum.git
synced 2026-08-24 00:00:16 +02:00
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:
@@ -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>());
|
||||
|
||||
Reference in New Issue
Block a user