Rebuild readme

This commit is contained in:
David Pedersen 2021-06-07 16:31:11 +02:00
parent d376e49eb9
commit d7605d3184
2 changed files with 20 additions and 18 deletions

View File

@ -1,7 +1,7 @@
# tower-web # tower-web
tower-web (name pending) is a tiny web application framework that focuses on tower-web (name pending) is a tiny web application framework that focuses on
ergonimics and modularity. ergonomics and modularity.
### Goals ### Goals
@ -9,7 +9,7 @@ ergonimics and modularity.
handle(Request) -> Response`. handle(Request) -> Response`.
- Solid foundation. tower-web is built on top of tower and makes it easy to - 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. plug in any middleware from the [tower] and [tower-http] ecosystem.
- Focus on routing, extracing data from requests, and generating responses. - Focus on routing, extracting data from requests, and generating responses.
tower middleware can handle the rest. tower middleware can handle the rest.
- Macro free core. Macro frameworks have their place but tower-web focuses - Macro free core. Macro frameworks have their place but tower-web focuses
on providing a core that is macro free. on providing a core that is macro free.
@ -454,7 +454,6 @@ use tower_web::{prelude::*, routing::BoxRoute, body::BoxBody};
use tower_http::services::ServeFile; use tower_http::services::ServeFile;
use http::Response; use http::Response;
use std::convert::Infallible; use std::convert::Infallible;
use tower::{service_fn, BoxError};
fn api_routes() -> BoxRoute<BoxBody> { fn api_routes() -> BoxRoute<BoxBody> {
route("/users", get(|_: Request<Body>| async { /* ... */ })).boxed() route("/users", get(|_: Request<Body>| async { /* ... */ })).boxed()
@ -464,5 +463,22 @@ let app = route("/", get(|_: Request<Body>| async { /* ... */ }))
.nest("/api", api_routes()); .nest("/api", api_routes());
``` ```
`nest` can also be used to serve static files from a directory:
```rust
use tower_web::{prelude::*, ServiceExt, routing::nest};
use tower_http::services::ServeDir;
use http::Response;
use std::convert::Infallible;
use tower::{service_fn, BoxError};
let app = nest(
"/images",
ServeDir::new("public/images").handle_error(|error: std::io::Error| {
// ...
})
);
```
[tower]: https://crates.io/crates/tower [tower]: https://crates.io/crates/tower
[tower-http]: https://crates.io/crates/tower-http [tower-http]: https://crates.io/crates/tower-http

View File

@ -1,5 +1,5 @@
//! tower-web (name pending) is a tiny web application framework that focuses on //! tower-web (name pending) is a tiny web application framework that focuses on
//! ergonimics and modularity. //! ergonomics and modularity.
//! //!
//! ## Goals //! ## Goals
//! //!
@ -57,7 +57,6 @@
//! async fn get_foo(req: Request<Body>) { //! async fn get_foo(req: Request<Body>) {
//! // `GET /foo` called //! // `GET /foo` called
//! } //! }
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -136,7 +135,6 @@
//! .route("/json", get(json)) //! .route("/json", get(json))
//! .route("/result", get(result)) //! .route("/result", get(result))
//! .route("/response", get(response)); //! .route("/response", get(response));
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -171,7 +169,6 @@
//! //!
//! // ... //! // ...
//! } //! }
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -192,7 +189,6 @@
//! //!
//! // ... //! // ...
//! } //! }
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -232,7 +228,6 @@
//! //!
//! // ... //! // ...
//! } //! }
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -261,7 +256,6 @@
//! ); //! );
//! //!
//! async fn handler(req: Request<Body>) {} //! async fn handler(req: Request<Body>) {}
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -282,7 +276,6 @@
//! async fn get_slash(req: Request<Body>) {} //! async fn get_slash(req: Request<Body>) {}
//! //!
//! async fn post_foo(req: Request<Body>) {} //! async fn post_foo(req: Request<Body>) {}
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -332,7 +325,6 @@
//! ); //! );
//! //!
//! async fn handle(req: Request<Body>) {} //! async fn handle(req: Request<Body>) {}
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -359,7 +351,6 @@
//! }); //! });
//! //!
//! async fn handle(req: Request<Body>) {} //! async fn handle(req: Request<Body>) {}
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -413,7 +404,6 @@
//! Cow::from(format!("Unhandled internal error: {}", error)), //! Cow::from(format!("Unhandled internal error: {}", error)),
//! ); //! );
//! }); //! });
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -446,7 +436,6 @@
//! //!
//! // ... //! // ...
//! } //! }
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -483,7 +472,6 @@
//! .handle_error(|error: std::io::Error| { /* ... */ }) //! .handle_error(|error: std::io::Error| { /* ... */ })
//! ) //! )
//! ); //! );
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -507,7 +495,6 @@
//! //!
//! let app = route("/", get(|_: Request<Body>| async { /* ... */ })) //! let app = route("/", get(|_: Request<Body>| async { /* ... */ }))
//! .nest("/api", api_routes()); //! .nest("/api", api_routes());
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };
@ -528,7 +515,6 @@
//! // ... //! // ...
//! }) //! })
//! ); //! );
//! #
//! # async { //! # async {
//! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await; //! # hyper::Server::bind(&"".parse().unwrap()).serve(tower::make::Shared::new(app)).await;
//! # }; //! # };