HTTP Clients

reqwest

reqwest reqwest-crates.io reqwest-github reqwest-lib.rs

reqwest is a full-fat HTTP client. It can be used in both synchronous and asynchronous code. It requires the tokio runtime.

Multiple examples using reqwest are found in APIs, Download, Requests.

ureq

ureq ureq-crates.io ureq-github ureq-lib.rs cat-web-programming::http-client

ureq is a minimal synchronous HTTP client, focused on simplicity and minimizing dependencies.

/// This example demonstrates a simple HTTP GET request using the `ureq` crate.
/// It fetches data from a public API endpoint and prints the response.
fn main() -> anyhow::Result<()> {
    // Define the URL to fetch data from.
    let url = "https://jsonplaceholder.typicode.com/posts/1";
    // Send a GET request to the URL and read the response body as a string.
    let response: String =
        // Make a GET request.
        ureq::get(url)
        // Send the request and blocks the caller until we receive a response.
        .call()?
        // Return a mutable reference to the associated HTTP body.
        .body_mut()
        .read_to_string()?;

    println!("Response: {}", response);
    Ok(())
}

Build a HTTP Client with hyper

hyper-website hyper hyper-crates.io hyper-github hyper-lib.rs cat-network-programming cat-web-programming::http-client cat-web-programming::http-server

hyper is a HTTP/1 and HTTP/2 implementation (both client and server) that works best with the tokio async runtime, but can support other runtimes.

hyper is meant to be a low-level building block and is indeed used by higher-level libraries such as curl, reqwest, and aws-sdk. You will likely reach for hyper to design such tools or access to bleeding-edge features (like HTTP/3).

// // COMING SOON

References