brio

Toy async http server and web framework

MIT licensed

```rust

![feature(async_closure)]

use brio::{App, Ctx, Request, Response, Status}; use log::info; use std::{future::Future, pin::Pin, time::Instant};

type BoxFuture<'a, Response> = Pin + Send + 'static>>;

async fn foo(: Request) -> Response { Response::withstatus(Status::Ok) }

fn main() { std::env::setvar("RUSTLOG", "brio=info,server=debug"); envlogger::init(); let mut app = App::new(); app.get("/foo", foo); app.get("/bar", async move |req: Request| { Response::with_status(Status::Ok) }); app.middleware("*", logger); app.files("/public/", "./examples/static/"); app.run(8000).unwrap(); }

fn logger(ctx: Ctx) -> BoxFuture { let now = Instant::now(); let path = ctx.req().route().path().clone(); let method = ctx.req().route().method().unwrap().clone(); let fut = ctx.next(); Box::pin(async move { let res = fut.await; info!( "request {} {} took {:?} ({})", method, path, Instant::now().duration_since(now), res.status() as u32 ); res }) } ```