areq

Crates.ioareq
lib.rsareq
version0.1.0-alpha5
created_at2024-11-05 01:16:26.656507+00
updated_at2025-08-29 20:17:20.46841+00
descriptionAsync runtime-agnostic HTTP requests
homepage
repositoryhttps://github.com/nanoqsh/areq
max_upload_size
id1435887
size70,740
Nano (nanoqsh)

documentation

https://docs.rs/areq

README

areq

Async runtime agnostic HTTP requests

Development

🚧 The library is currently under development 🚧

Many features require an unstable Rust feature – return type notation. The main crate areq has the rtn feature, which enables the missing functionality. High-level crates areq-smol and areq-tokio require this feature for compilation, so to use the library you need to install nightly compiler. Once the RTN feature is stabilized, the library will be usable on stable.

Features

  • Async only, no hidden overhead from blocking API
  • Independent of any async runtime, including features. Instead, the runtime extends the functionality of the base crate
  • Zero-cost abstractions for a flexible solution and an ability to choose a simple API when needed
  • Modular and configurable – build exactly the HTTP client you need

Getting Started

Although the library is runtime-agnostic, it also provides high-level crates for choosing a specific runtime. Currently, two crates are available:

As an example, let's use tokio and add the crate to a project. You also need to select an HTTP protocol version that the client will support. For this example, let's use HTTP/1.1 which can be enabled with the http1 cargo feature:

cargo add areq-tokio -F http1

Now you can make a GET request and read a response body:

use {
    areq_tokio::{areq::{http::Uri, http1::Http1}, prelude::*},
    std::io::Error,
};

async fn get() -> Result<String, Error> {
    let uri = Uri::from_static("http://127.0.0.1:3001/hello");
    let (mut client, conn) = Http1::default().connect(&uri).await?;
    tokio::spawn(conn);

    client.get(uri, ()).await?.text().await
}

fn main() {
    let rt = tokio::runtime::Runtime::new();
    match rt.and_then(|rt| rt.block_on(get())) {
        Ok(text) => println!("{text}"),
        Err(e) => eprintln!("io error: {e}"),
    }
}
Commit count: 161

cargo fmt