hteapot 0.6.5

HTeaPot is a lightweight HTTP server library designed to be easy to use and extend.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use hteapot::{Hteapot, HttpRequest, HttpResponse, HttpStatus};

fn main() {
    let server = Hteapot::new("localhost", 8081);
    server.listen(move |req: HttpRequest| {
        // This will be executed for each request
        let body = String::from_utf8(req.body).unwrap_or("NOPE".to_string());
        for header in req.headers {
            println!("- {}: {}", header.0, header.1);
        }
        println!("{}", body);
        HttpResponse::new(
            HttpStatus::IAmATeapot,
            format!("Hello, I am HTeaPot\n{}", body),
            None,
        )
    });
}