#http-server #http #web #http-request #light-weight #hash-map

httplite

A super lightweight HTTP server written in Rust, made to resemble the functionality of the "NET/HTTP" module in Go

4 releases

0.1.3 Jun 24, 2024
0.1.2 Jun 24, 2024
0.1.1 Jun 24, 2024
0.1.0 Jun 11, 2024

#1842 in Web programming

Download history 288/week @ 2024-06-20 60/week @ 2024-06-27 36/week @ 2024-07-04 9/week @ 2024-07-25 2/week @ 2024-08-01 20/week @ 2024-09-12 4/week @ 2024-09-19 26/week @ 2024-09-26 8/week @ 2024-10-03

58 downloads per month

Apache-2.0

8KB
159 lines

httplite

A super lightweight HTTP server written in Rust, made to resemble the functionality of the "NET/HTTP" module in Go. Still in early access and working on docs.

Installing httplite

Include this is your Cargo.toml in your project. [dependencies] httplite = "0.1.3"

Basic examples

Hello world example:

use httplite::{Httplite, ResponseWriter, Request};

fn main() {
    println!("Server is running at http://localhost:8080");
    let port = Httplite::new(":8080");
    port.add_route("/hello", hello_server);
    port.listen().unwrap();
}

fn hello_server(mut w: ResponseWriter, r: Request) {
    let response_text = format!("Hello, {}", r.url().trim_start_matches("/hello/"));
    w.print_text(&response_text).unwrap();
}

Hosting JSON example:

use httplite::{Httplite, ResponseWriter, Request};
use std::collections::HashMap;

fn main() {
    println!("Server is running at http://localhost:8080");
    let port = Httplite::new(":8080");
    port.add_route("/json", json_server);
    port.listen().unwrap();
}

fn json_server(mut w: ResponseWriter, _r: Request) {
    let mut map = HashMap::new();
    map.insert("JSON Thing", "This is a thing");
    map.insert("Another JSON Thing", "This is another thing");
    w.print_hashmap_to_json(&map).unwrap();
}

Latest Notable Updates

0.1.3 Added the ability to host hashmaps as serialized json on an endpoint.

No runtime deps