tinyhttp, a small http library made by me

Posted: June 2022

I wrote a HTTP library as a project to help learn Rust. It uses a procedural macro crate under the hood. Procedural macros in Rust are extremely powerful.

They allow for clean, good looking code like:

use std::net::TcpListener; use tinyhttp::prelude::*; #[get("/")] fn get(_req: Request) -> &'static str { "Hello, World!" } fn main() { let socket = TcpListener::bind(":::80").unwrap(); let routes = Routes::new(vec![get(), post()]); let config = Config::new().routes(routes); let http = HttpListener::new(socket, config); http.start(); }

The #[get("/")] allows you to minipulate the tokenization process at compile-time, proving to be a powerful tool.

It goes from:

#[get("/")] fn get() -> &'static str { "Hello, World!" }

Into:

Performance

I haven't been able to test with two proper desktops, however with my i7-4770k as a client and my Raspberry Pi 4 as the server, the Raspberry Pi 4 was able to handle around 15000 req/s.

made by ~~> Mateo