httpageboy 1.0.5

Handle HTTP request/response transmission on the server side without processing.
Documentation

HTTPageboy Server

Minimal HTTP server package for handling request/response transmission.

Request: any HTTP request. Route: path + method + handler → returns Response. Response: bytes with content-type, sent to browser.

Example

Creating a simple server:

use httpageboy::{Request, Response, Rt, Server, StatusCode}; // Rt is alias for ResponseType

fn main() {
    let serving_url: &str = "127.0.0.1:7878";
    let threads_number: u8 = 10;
    let mut server = Server::new(serving_url, threads_number, None).unwrap();
    server.add_route("/demo", Rt::GET, demo_get);
    server.add_route("/demo", Rt::POST, demo_post);
    server.run();
}

fn demo_get(_request: &Request) -> Response {
    return Response {
        status: StatusCode::Ok.to_string(),
        content_type: String::new(),
        content: "get".as_bytes().to_vec(),
    };
}

fn demo_post(_request: &Request) -> Response {
    return Response {
        status: StatusCode::Ok.to_string(),
        content_type: String::new(),
        content: "post".as_bytes().to_vec(),
    };
}

Dependencies

There are no external dependencies for production. :)

There are two deps for testing only.

License

Copyright (c) 2024 fahedsl This project is licensed under the MIT License.