| Crates.io | small-http |
| lib.rs | small-http |
| version | 0.2.1 |
| created_at | 2025-02-21 19:34:40.422308+00 |
| updated_at | 2025-09-11 08:55:45.334241+00 |
| description | A simple and small sync HTTP/1.1 server/client library |
| homepage | https://github.com/bplaat/crates/tree/master/lib/small-http |
| repository | https://github.com/bplaat/crates |
| max_upload_size | |
| id | 1564621 |
| size | 80,109 |
A simple and small HTTP/1.1 server/client library
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.
url dependenciesYou 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
See the documentation for more information.
Copyright © 2023-2025 Bastiaan van der Plaat
Licensed under the MIT license.