Fast, robust, flexible, lightweight web framework for Rust
Note: viz's main branch is currently preparing breaking changes. For the most recently released code, look to the 0.4.x branch.
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.
This project is licensed under the MIT license.