#http-router #tower-service #http-request #builder #async

router-service

A simple HTTP router to be used as a tower service

2 unstable releases

0.2.0 Jun 15, 2023
0.1.0 Jun 15, 2023

#17 in #http-router

MIT license

29KB
614 lines

router-service

A simple HTTP request Router that can be used as a tower Service

WIP


lib.rs:

A simple no-frills router that can be used as a Service.

Example

use std::convert::Infallible;
use std::net::SocketAddr;

use http::{Request, Response, StatusCode};
use hyper::{Server, Body};
use tower::{Service, make::Shared};
use router_service::Router;

let mut router = Router::new()
    .get("/", |req, _| async move {
        println!("Got request with headers: {:#?}", req.headers());
        Response::builder().body(Body::empty())
    });

 let addr = ([127, 0, 0, 1], 3030).into();
 Server::bind(&addr)
    .serve(Shared::new(router))
    .await
    .expect("error running server");

Dependencies

~1.5MB
~31K SLoC