blocking-http-server

Crates.ioblocking-http-server
lib.rsblocking-http-server
version0.1.3
created_at2025-03-10 13:35:00.084119+00
updated_at2025-03-20 08:12:26.873912+00
descriptionA simple Blocking HTTP server library
homepage
repositoryhttps://github.com/hangj/blocking-http-server
max_upload_size
id1586647
size14,317
hangj (hangj)

documentation

https://docs.rs/blocking-http-server/

README

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"));
            }
            _ => {
                let _ = req.respond(
                    Response::builder()
                        .status(StatusCode::NOT_FOUND)
                        .body("404 Not Found")
                        .unwrap(),
                );
             }
        }
    }
    Ok(())
}
Commit count: 16

cargo fmt