Crate humphrey[−][src]
Expand description
Humphrey: A Performance-Focused, Dependency-Free Web Server.
Humphrey is a very fast, robust and flexible HTTP/1.1 web server crate which allows you to develop web applications in Rust. With no dependencies, it is very quick to compile and produces very small binaries, as well as being very resource-efficient.
Installation
The Humphrey crate can be installed by adding humphrey
to your Cargo.toml file.
Basic Example
use humphrey::http::{Request, Response, StatusCode};
use humphrey::App;
use std::{error::Error, sync::Arc};
fn main() -> Result<(), Box<dyn Error>> {
let app = App::new()
.with_route("/", home)
.with_route("/contact", contact);
app.run("0.0.0.0:80")?;
Ok(())
}
fn home(request: Request, _: Arc<()>) -> Response {
Response::new(StatusCode::OK, b"<html><body><h1>Home</h1></body></html>", &request)
}
fn contact(request: Request, _: Arc<()>) -> Response {
Response::new(StatusCode::OK, b"<html><body><h1>Contact</h1></body></html>", &request)
}
Further Examples
- Stateful Example: keeps track of button presses across sessions and devices
- Wildcard Example: demonstrates a wildcard route
- Static Content Example: demonstrates the built-in static content handlers
Re-exports
pub use app::App;