Fast, robust, flexible, lightweight web framework for Rust
Safety #![forbid(unsafe_code)]
Lightweight
Robust Routing
Handy Extractors
Simple + Flexible Handler
& Middleware
```rust use std::{net::SocketAddr, sync::Arc}; use tokio::net::TcpListener; use viz::{server::conn::http1, Request, Responder, Result, Router, Tree};
async fn index(_: Request) -> Result<&'static str> { Ok("Hello, Viz!") }
async fn main() -> Result<()> { let addr = SocketAddr::from(([127, 0, 0, 1], 3000)); let listener = TcpListener::bind(addr).await?; println!("listening on {addr}");
let app = Router::new().get("/", index);
let tree = Arc::new(Tree::from(app));
loop {
let (stream, addr) = listener.accept().await?;
let tree = tree.clone();
tokio::task::spawn(async move {
if let Err(err) = http1::Builder::new()
.serve_connection(stream, Responder::new(tree, Some(addr)))
.await
{
eprintln!("Error while serving HTTP connection: {}", err);
}
});
}
} ```
More examples can be found here.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Viz by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.