touche 0.0.15

Synchronous HTTP library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use std::path::PathBuf;

use touche::{Body, Response, Server, StatusCode};

fn main() -> std::io::Result<()> {
    Server::bind("0.0.0.0:4444").serve(|_req| {
        match Body::try_from(PathBuf::from("./examples/file.rs")) {
            Ok(file) => Response::builder().status(StatusCode::OK).body(file),
            Err(_) => Response::builder()
                .status(StatusCode::NOT_FOUND)
                .body(Body::empty()),
        }
    })
}