1 unstable release
new 0.1.2 | Mar 10, 2025 |
---|
#418 in HTTP server
109 downloads per month
12KB
213 lines
A simple Blocking HTTP server library
No async, No runtime, just a dead simple blocking http server
Usage example:
use blocking_http_server::*;
fn main() -> anyhow::Result<()> {
let mut server = Server::bind("127.0.0.1:8000")?;
for req in server.incoming() {
let mut req = match req {
Ok(req) => req,
Err(e) => {
eprintln!("Error: {}", e);
continue;
}
};
match (req.method(), req.uri().path()) {
(&Method::GET, "/") => {
let _ = req.respond(Response::new("hello world".as_bytes()));
}
_ => {
let _ = req.respond(
Response::builder()
.status(StatusCode::NOT_FOUND)
.body("404 Not Found".as_bytes())
.unwrap(),
);
}
}
}
Ok(())
}
Dependencies
~775KB
~13K SLoC