Crate torus_http

Crate torus_http 

Source
Expand description

§toy-rusttp

A small, synchronous http server library with a surprisingly pleasant developer experience and minimal moving parts.

§Example usage:

use toy_rusttp::prelude::*;

fn main() {
    let server: HttpServer<_> = HttpServer::new(("127.0.0.1", 8080))
        .get("/", hello_world)
        .route(
            "/hello",
            HttpMethod::Other("custom".into()),
            |_| "hello from a custom method",
        )
        .add_middleware(|req| {
            println!("got request: {req:#?}");
            req
        });

    _ = server.run();
}

pub fn hello_world(req: Request) -> impl Response {
    format!(
        "hello, kind world... I will now proceed to print your headers: {:#?}",
        req.headers
    )
}

Modules§

method
Contains safe wrappers for http methods, note that the conversion is case insensitive so custom methods might not behave as expected
prelude
Re-export of the common things required for making a rudimentary http server
request
This module handles parsing the client’s request into a simple to work with data structure
response
Exports a trait for generating http responses, with a simple default implementation for string bodies.
server
The actual http server on which you define your routes
status
Http status wrapper