tiny-http-server is a simple blocking http server crate.
Example usage:
use std::net::Ipv4Addr;
use tiny_http_server::{
http::{Response, StatusCode},
server::Server,
};
const ADDRESS: (Ipv4Addr, u16) = (Ipv4Addr::UNSPECIFIED, 5000);
fn main() {
let server = Server::bind(ADDRESS).unwrap();
let _ = server.run(|req| {
let response = match req.uri().path() {
"/" => Response::builder()
.status(StatusCode::OK)
.header("Content-Type", "text/plain")
.body("Hello World!".to_string())
.unwrap(),
_ => Response::builder()
.status(StatusCode::NOT_FOUND)
.body("404 Not Found".to_string())
.unwrap(),
};
response
});
}