mirror of
https://github.com/tokio-rs/axum.git
synced 2025-01-11 12:31:25 +01:00
Update docs with nesting
This commit is contained in:
parent
1609191a74
commit
91b1b0bc50
2 changed files with 38 additions and 18 deletions
26
README.md
26
README.md
|
@ -5,7 +5,7 @@ ergonimics and modularity.
|
|||
|
||||
### Goals
|
||||
|
||||
- Ease of use. Build web apps in Rust should be as easy as `async fn
|
||||
- Ease of use. Building web apps in Rust should be as easy as `async fn
|
||||
handle(Request) -> Response`.
|
||||
- Solid foundation. tower-web is built on top of tower and makes it easy to
|
||||
plug in any middleware from the [tower] and [tower-http] ecosystem.
|
||||
|
@ -14,13 +14,6 @@ tower middleware can handle the rest.
|
|||
- Macro free core. Macro frameworks have their place but tower-web focuses
|
||||
on providing a core that is macro free.
|
||||
|
||||
### Non-goals
|
||||
|
||||
- Runtime independent. tower-web is designed to work with tokio and hyper
|
||||
and focused on bringing a good to experience to that stack.
|
||||
- Speed. tower-web is a of course a fast framework, and wont be the
|
||||
bottleneck in your app, but the goal is not to top the benchmarks.
|
||||
|
||||
## Example
|
||||
|
||||
The "Hello, World!" of tower-web is:
|
||||
|
@ -454,7 +447,22 @@ See the [`service`] module for more details.
|
|||
|
||||
## Nesting applications
|
||||
|
||||
TODO
|
||||
Applications can be nested by calling `nest`:
|
||||
|
||||
```rust
|
||||
use tower_web::{prelude::*, routing::BoxRoute, body::BoxBody};
|
||||
use tower_http::services::ServeFile;
|
||||
use http::Response;
|
||||
use std::convert::Infallible;
|
||||
use tower::{service_fn, BoxError};
|
||||
|
||||
fn api_routes() -> BoxRoute<BoxBody> {
|
||||
route("/users", get(|_: Request<Body>| async { /* ... */ })).boxed()
|
||||
}
|
||||
|
||||
let app = route("/", get(|_: Request<Body>| async { /* ... */ }))
|
||||
.nest("/api", api_routes());
|
||||
```
|
||||
|
||||
[tower]: https://crates.io/crates/tower
|
||||
[tower-http]: https://crates.io/crates/tower-http
|
||||
|
|
30
src/lib.rs
30
src/lib.rs
|
@ -3,7 +3,7 @@
|
|||
//!
|
||||
//! ## Goals
|
||||
//!
|
||||
//! - Ease of use. Build web apps in Rust should be as easy as `async fn
|
||||
//! - Ease of use. Building web apps in Rust should be as easy as `async fn
|
||||
//! handle(Request) -> Response`.
|
||||
//! - Solid foundation. tower-web is built on top of tower and makes it easy to
|
||||
//! plug in any middleware from the [tower] and [tower-http] ecosystem.
|
||||
|
@ -12,13 +12,6 @@
|
|||
//! - Macro free core. Macro frameworks have their place but tower-web focuses
|
||||
//! on providing a core that is macro free.
|
||||
//!
|
||||
//! ## Non-goals
|
||||
//!
|
||||
//! - Runtime independent. tower-web is designed to work with tokio and hyper
|
||||
//! and focused on bringing a good to experience to that stack.
|
||||
//! - Speed. tower-web is a of course a fast framework, and wont be the
|
||||
//! bottleneck in your app, but the goal is not to top the benchmarks.
|
||||
//!
|
||||
//! # Example
|
||||
//!
|
||||
//! The "Hello, World!" of tower-web is:
|
||||
|
@ -500,7 +493,26 @@
|
|||
//!
|
||||
//! # Nesting applications
|
||||
//!
|
||||
//! TODO
|
||||
//! Applications can be nested by calling `nest`:
|
||||
//!
|
||||
//! ```rust,no_run
|
||||
//! use tower_web::{prelude::*, routing::BoxRoute, body::BoxBody};
|
||||
//! use tower_http::services::ServeFile;
|
||||
//! use http::Response;
|
||||
//! use std::convert::Infallible;
|
||||
//! use tower::{service_fn, BoxError};
|
||||
//!
|
||||
//! fn api_routes() -> BoxRoute<BoxBody> {
|
||||
//! route("/users", get(|_: Request<Body>| async { /* ... */ })).boxed()
|
||||
//! }
|
||||
//!
|
||||
//! let app = route("/", get(|_: Request<Body>| async { /* ... */ }))
|
||||
//! .nest("/api", api_routes());
|
||||
//! #
|
||||
//! # async {
|
||||
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
|
||||
//! # };
|
||||
//! ```
|
||||
//!
|
||||
//! [tower]: https://crates.io/crates/tower
|
||||
//! [tower-http]: https://crates.io/crates/tower-http
|
||||
|
|
Loading…
Reference in a new issue