Ergonomic and modular web framework built with Tokio, Tower, and Hyper https://crates.io/crates/axum
Find a file
David Pedersen 04d62798b6
Reduce body boxing (#9)
Previously, when routing between one or two requests the two body types
would be merged by boxing them. This isn't ideal since it introduces a
layer indirection for each route.

We can't require the services to be routed between as not all services
use the same body type.

This changes that so it instead uses an `Either` enum that implements
`http_body::Body` if each variant does. Will reduce the overall
allocations and hopefully the compiler can optimize things if both
variants are the same.
2021-06-12 23:59:18 +02:00
.github Add RoutingDsl::{serve, into_make_service} (#8) 2021-06-12 21:44:40 +02:00
examples Reduce body boxing (#9) 2021-06-12 23:59:18 +02:00
src Reduce body boxing (#9) 2021-06-12 23:59:18 +02:00
.gitignore Initial pile of hacks 2021-05-29 21:13:06 +02:00
Cargo.toml Reduce body boxing (#9) 2021-06-12 23:59:18 +02:00
CHANGELOG.md Misc repo setup (#7) 2021-06-12 20:18:21 +02:00
CONTRIBUTING.md Misc repo setup (#7) 2021-06-12 20:18:21 +02:00
deny.toml Misc repo setup (#7) 2021-06-12 20:18:21 +02:00
LICENSE Misc repo setup (#7) 2021-06-12 20:18:21 +02:00
README.md Misc repo setup (#7) 2021-06-12 20:18:21 +02:00

tower-web

WARNING: tower-web is very much still work in progress. Nothing is released to crates.io yet and you shouldn't be using this in production.

tower-web (name pending) is a tiny web application framework that focuses on ergonomics and modularity.

Build status

More information about this crate can be found in the crate documentation.

Goals

  • 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.
  • Focus on routing, extracting data from requests, and generating responses. 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.

Usage example

use tower_web::prelude::*;
use hyper::Server;
use std::net::SocketAddr;
use tower::make::Shared;

#[tokio::main]
async fn main() {
    // build our application with a single route
    let app = route("/", get(|| async { "Hello, World!" }));

    // run it with hyper on localhost:3000
    let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
    Server::bind(&addr)
        .serve(Shared::new(app))
        .await
        .unwrap();
}

Examples

The examples folder contains various examples of how to use tower-web. The docs also have lots of examples

Getting Help

If you're new to tower its [guides] might help. In the tower-web repo we also have a number of examples showing how to put everything together. You're also welcome to ask in the #tower Discord channel or open an issue with your question.

Contributing

🎈 Thanks for your help improving the project! We are so happy to have you! We have a contributing guide to help you get involved in the tower-web project.

License

This project is licensed under the MIT license.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in tower-web by you, shall be licensed as MIT, without any additional terms or conditions.