Crate alhc

source ·
Expand description

Async Lightweight HTTP Client (aka ALHC)

WARNING This library is still in development and VERY UNSTABLE, please don’t use it in production environment.

github.com crates.io docs.rs

What if we need async but also lightweight http client without using such a large library like reqwest, isahc or surf?

ALHC is a async http client library that using System library to reduce binary size and provide async request feature.

HTTPS Example:

use alhc::prelude::*;
use alhc::*;

use pollster::FutureExt;

fn main() -> DynResult {
    let client = get_client_builder().build().unwrap();

    let r = client
        .post("https://httpbin.org/anything")?
        .header("user-agent", "alhc/0.2.0")
        .body_string("Hello World!".repeat(20))
        .block_on()?
        .recv_string()
        .block_on()?;

    println!("{r}");

    Ok(())
}

Our little request example https with release build can be 182 KB, which is smaller than tinyget’s http example. If we use rustc nightly feature plus build-std and panic_immediate_abort, it’ll be incredibly 60 KB!

Currently work in progress and only support Windows (Using WinHTTP) and macOS in progress (Using CFNetwork), linux are being planned.

Platform Status

NameStatusNote
WindowsWorking
MacOSWorkingWill block the thread currently (To be fixed)
LinuxUnder Development

Features

  • async_t_boxed: Use async-trait instead of async-t, which requires nightly rustc but with zero-cost. Default is enabled.
  • serde: Can give you the ability of send/receive json data without manually call serde_json. Default is disabled.

Compilation binary size comparison

Note: the size optimization argument is: cargo +nightly run --release -Z build-std=core,alloc,std,panic_abort -Z build-std-features=panic_immediate_abort --target [TARGET] --example [EXAMPLE] and some configuration in Cargo.toml

NameWindows (x86_64)Windows (i686)Windows (aarch64)macOS (x86_64)macOS (aarch64)Linux (x86_64)
example https397,824284,160296,960950,512992,152WIP
example https release181,760187,904200,192336,848323,048/
example https release with size optimization60,41652,22459,39289,05689,944/
example parallel520,704376,320393,2161,130,4481,192,536/
example parallel release195,072211,456229,888353,216339,576/
example parallel release with size optimization66,56058,88066,560105,440106,456/
example sequential402,432289,280302,080952,720994,920/
example sequential release185,344191,488203,264336,792323,000/
example sequential release with size optimization62,46454,78460,92889,01689,896/

Modules

Structs

Enums

Functions

Type Aliases