You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fast: Fully asynchronous, built on Tokio and Hyper.
Ergonomic: Tower-web decouples HTTP from your application logic, removing
all boilerplate.
Works on Rust stable: You can use it today.
Hello World
#[macro_use]externcrate tower_web;externcrate tokio;use tower_web::ServiceBuilder;use tokio::prelude::*;/// This type will be part of the web service as a resource.#[derive(Clone,Debug)]structHelloWorld;/// This will be the JSON response#[derive(Response)]structHelloResponse{message:&'staticstr,}impl_web!{implHelloWorld{
#[get("/")]
#[content_type("json")]fn hello_world(&self) -> Result<HelloResponse,()> {Ok(HelloResponse{
message:"hello world",})}}}pubfnmain(){let addr = "127.0.0.1:8080".parse().expect("Invalid address");println!("Listening on https://{}", addr);ServiceBuilder::new().resource(HelloWorld).run(&addr).unwrap();}
Overview
Tower Web aims to decouple all HTTP concepts from the application logic. You
define a "plain old Rust method" (PORM?). This method takes only the data it
needs to complete and returns a struct representing the response. Tower Web does
the rest.
The impl_web macro looks at the definition and generates the glue code,
allowing the method to respond to HTTP requests.
Getting Started
The best way to get started is to read the examples and API docs.
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.