| Crates.io | blocking-http-server |
| lib.rs | blocking-http-server |
| version | 0.1.3 |
| created_at | 2025-03-10 13:35:00.084119+00 |
| updated_at | 2025-03-20 08:12:26.873912+00 |
| description | A simple Blocking HTTP server library |
| homepage | |
| repository | https://github.com/hangj/blocking-http-server |
| max_upload_size | |
| id | 1586647 |
| size | 14,317 |
No async, No runtime, just a dead simple blocking http server
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"));
}
_ => {
let _ = req.respond(
Response::builder()
.status(StatusCode::NOT_FOUND)
.body("404 Not Found")
.unwrap(),
);
}
}
}
Ok(())
}