Crates.io | grout |
lib.rs | grout |
version | 0.2.0 |
source | src |
created_at | 2020-08-23 07:39:17.040325 |
updated_at | 2020-08-26 14:18:16.011206 |
description | A dead simple hash-based HTTP router built on hyper. |
homepage | |
repository | https://github.com/appellation/grout |
max_upload_size | |
id | 279743 |
size | 29,499 |
A dead simple hash-based HTTP router built on hyper.
use grout::{path, Body, Method, Request, Response, ResponseBuilder, RouterBuilder, Server};
async fn handler(params: Vec<String>, _req: Request) -> Response {
Ok(ResponseBuilder::default().body(Body::empty())?)
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let addr = ([127, 0, 0, 1], 3000).into();
let router = RouterBuilder::default()
.register(Method::GET, path![], handler)
.register(Method::GET, path![foo / _], handler)
.register(Method::POST, path![foo / _], handler)
.build();
let server = Server::bind(&addr).serve(router);
println!("Listening on http://{}", addr);
server.await?;
Ok(())
}
See the examples folder for example usage.
state
crate to inject outside
structs into your route handlers