Thanks to visit codestin.com
Credit goes to lib.rs

3 unstable releases

0.2.1 Sep 11, 2025
0.2.0 Jun 27, 2025
0.1.0 Feb 21, 2025

#467 in HTTP server

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

184 downloads per month
Used in small-router

MIT license

58KB
1K SLoC

Small-HTTP Rust library

A simple and small HTTP/1.1 server/client library

Getting Started

A simple example the opens a http server on serves a simple response:

use std::net::{Ipv4Addr, TcpListener};
use small_http::{Request, Response};

fn handler(_req: &Request) -> Response {
    Response::with_body("Hello World!")
}

fn main() {
    let listener = TcpListener::bind((Ipv4Addr::LOCALHOST, 8080))
        .unwrap_or_else(|_| panic!("Can't bind to port"));
    small_http::serve(listener, handler);
}

A simple example the of a http client that fetches a JSON response:

#[derive(serde::Deserialize)]
struct IpInfo {
    hostname: String,
}

fn main() {
    let res = small_http::Request::get("http://ipinfo.io/json")
        .fetch()
        .expect("Can't fetch");
    println!("{}", String::from_utf8_lossy(&res.body));
    let ip_info = res.into_json::<IpInfo>().expect("Can't parse JSON");
    println!("Hostname: {}", ip_info.hostname);
}

See the examples for many more examples.

Important: reduce url dependencies

You can greatly reduce the dependencies of the url crate, by removing the idna support with the following crate update:

cargo update -p idna_adapter --precise 1.0.0

Documentation

See the documentation for more information.

License

Copyright © 2023-2025 Bastiaan van der Plaat

Licensed under the MIT license.

Dependencies

~2.6–4MB
~71K SLoC