#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

#1153 in Text processing

Download history 7/week @ 2024-02-17 31/week @ 2024-02-24 10/week @ 2024-03-02 42/week @ 2024-03-30 9/week @ 2024-04-06

51 downloads per month

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

~7–16MB
~208K SLoC