#web #http #api #web-server

libwizard

A crate for creating a simple http web server or a (somewhat static) API

3 releases

0.1.3 Jul 19, 2023
0.1.2 Jul 19, 2023
0.1.1 Jul 19, 2023

#397 in #web-server

MIT license

17KB
416 lines

HTML-rs

Simple rust library to write and server html directly from a program

Example

use libwizard::prelude::*;

fn main() {
    let server = Server::new("127.0.0.1", 8080);
    let custom_routes = vec![
        CustomRoutes::new(
            "/about",
            "text/html",
            include_html("./about.html"),
            Some("./about.css"),
        ),
        CustomRoutes::new(
            "/api",
            "application/json",
            "{\"name\": \"John\", \"age\": 30}",
            None::<String>,
        ),
    ];

    server.start(
        ServerResponse::new(include_html("./index.html")),
        StyleResponse::new("./style.css"),
        custom_routes,
        Custom404::new(include_html("./404.html")),
    );
}

Dependencies

~6–14MB
~183K SLoC