Reqwest — Ergonomic HTTP Client for Rust
Reqwest is the most popular HTTP client library for Rust. It provides a high-level, async API for making HTTP requests with automatic JSON serialization, TLS, cookie management, proxy support, and connection pooling — the Rust equivalent of Python requests.
What it is
Reqwest is the most widely used HTTP client library for Rust. It provides a high-level, async-first API for making HTTP requests with automatic JSON serialization via serde, native TLS or rustls, cookie management, proxy support, connection pooling, and redirect handling. It sits on top of hyper for the HTTP layer and tokio for async runtime.
Reqwest targets Rust developers building API clients, web scrapers, microservice integrations, or any application that needs to make HTTP calls. It is the Rust equivalent of Python's requests library.
How it saves time or tokens
Using hyper directly requires manually handling connection management, TLS configuration, body streaming, and response parsing. Reqwest wraps all of this in a clean API. A JSON POST request that would take 20+ lines with hyper takes 3 lines with reqwest. The built-in connection pool reuses TCP connections automatically, improving throughput without extra code.
How to use
- Add reqwest with JSON support:
cargo add reqwest --features jsonand add tokio:cargo add tokio --features full. - Create a
reqwest::Client(reuse it across requests for connection pooling). - Call
.get(),.post(),.json(), etc. and.awaitthe response.
Example
use reqwest;
use serde::Deserialize;
#[derive(Deserialize, Debug)]
struct User {
login: String,
id: u64,
public_repos: u32,
}
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
// Simple GET
let body = reqwest::get('https://httpbin.org/get')
.await?
.text()
.await?;
println!('Body: {}', &body[..100]);
// Typed JSON response
let user: User = reqwest::get('https://api.github.com/users/rust-lang')
.await?
.json()
.await?;
println!('User: {:?}', user);
Ok(())
}
Related on TokRepo
- Coding Tools -- Developer libraries and utilities
- Web Scraping Tools -- HTTP clients and scraping frameworks
Common pitfalls
- Creating a new
reqwest::Clientper request instead of reusing one. Each client creates its own connection pool and TLS sessions, wasting resources. - Forgetting to enable the
jsonfeature flag and getting compile errors when calling.json()on responses. - Using the blocking client (
reqwest::blocking) inside an async runtime, which panics. Use the async API within tokio/async-std contexts.
Frequently Asked Questions
Yes. Reqwest supports HTTP/2 via the h2 crate. When you connect to an HTTPS endpoint that supports HTTP/2, reqwest negotiates it automatically via ALPN. You can also force HTTP/2 with the client builder. HTTP/2 multiplexes multiple requests over a single connection, reducing latency.
Hyper is a low-level HTTP library that handles the protocol layer. Reqwest is a high-level client built on hyper that adds connection pooling, cookies, redirects, JSON serialization, and a simpler API. Use hyper when you need fine-grained control over the HTTP layer; use reqwest for everyday HTTP requests.
Reqwest provides a `blocking` module that wraps the async client in a synchronous API. This does not require tokio in your own code (reqwest spawns a runtime internally). However, the async API with tokio is the recommended approach for production applications.
By default, reqwest uses the platform's native TLS library (OpenSSL on Linux, Secure Transport on macOS, SChannel on Windows). You can switch to rustls (a pure-Rust TLS implementation) via the `rustls-tls` feature flag. Rustls avoids C dependencies and simplifies cross-compilation.
Yes. Use `.bytes_stream()` on a response to get a `Stream<Item = Result<Bytes>>` that you can process chunk by chunk. This is essential for downloading large files or processing server-sent events without loading the entire response into memory.
Citations (3)
- Reqwest GitHub— Reqwest is built on hyper and tokio for async HTTP
- Reqwest Documentation— Supports native-tls and rustls backends
- Hyper Documentation— Connection pooling and HTTP/2 support via hyper
Related on TokRepo
Discussion
Related Assets
Conda — Cross-Platform Package and Environment Manager
Install, update, and manage packages and isolated environments for Python, R, C/C++, and hundreds of other languages from a single tool.
Sphinx — Python Documentation Generator
Generate professional documentation from reStructuredText and Markdown with cross-references, API autodoc, and multiple output formats.
Neutralinojs — Lightweight Cross-Platform Desktop Apps
Build desktop applications with HTML, CSS, and JavaScript using a tiny native runtime instead of bundling Chromium.