Update docs with nesting

This commit is contained in:
David Pedersen
2021-06-06 20:39:54 +02:00
parent 1609191a74
commit 91b1b0bc50
2 changed files with 38 additions and 18 deletions
+17 -9
View File
@@ -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