Expand description
HTTP client for making web requests.
reqwest is a high-level HTTP client library built on top of hyper.
It provides both asynchronous and blocking APIs for making HTTP requests,
with support for JSON, form data, cookies, proxies, and TLS.
The async API uses Client as the main entry point.
For quick one-off requests, convenience functions like get are available.
The blocking API lives in the blocking module.
Common features include:
- Automatic handling of redirects and cookies
- JSON serialization/deserialization via serde
- Request timeouts and connection pooling
- TLS/HTTPS support via native-tls or rustls
- Multipart form data for file uploads
- Streaming request and response bodies
§Examples
Making a simple GET request (blocking):
use reqwest::blocking;
let body = blocking::get("https://httpbin.org/get")
.expect("request failed")
.text()
.expect("failed to read body");
println!("Response: {}", body);Making an async GET request:
use reqwest::Client;
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = Client::new();
let resp = client.get("https://httpbin.org/get")
.send()
.await?;
println!("Status: {}", resp.status());
println!("Body: {}", resp.text().await?);
Ok(())
}Posting JSON data:
use reqwest::Client;
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug)]
struct Payload {
name: String,
count: u32,
}
#[derive(Deserialize, Debug)]
struct Response {
json: Payload,
}
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let client = Client::new();
let payload = Payload {
name: "test".to_string(),
count: 42,
};
let resp: Response = client.post("https://httpbin.org/post")
.json(&payload)
.send()
.await?
.json()
.await?;
println!("Response: {:?}", resp);
Ok(())
}Modules§
- blocking
- A blocking Client API.
- dns
- DNS resolution
- header
- HTTP header types
- redirect
- Redirect Handling
- retry
- Retry requests
- tls
- TLS configuration and types
Structs§
- Body
- An asynchronous request body.
- Certificate
- Represents a server X509 certificate.
- Client
- An asynchronous
Clientto make Requests with. - Client
Builder - A
ClientBuildercan be used to create aClientwith custom configuration. - Error
- The Errors that may occur when processing a
Request. - Identity
- Represents a private key and X509 cert as a client certificate.
- Method
- The Request Method (VERB)
- NoProxy
- A configuration for filtering out requests that shouldn’t be proxied
- Proxy
- Configuration of a proxy that a
Clientshould pass requests to. - Request
- A request which can be executed with
Client::execute(). - Request
Builder - A builder to construct the properties of a
Request. - Response
- A Response to a submitted
Request. - Status
Code - An HTTP status code (
status-codein RFC 9110 et al.). - Upgraded
- An upgraded HTTP connection.
- Url
- A parsed URL record.
- Version
- Represents a version of the HTTP spec.
Traits§
- IntoUrl
- A trait to try to convert some type into a
Url. - Response
Builder Ext - Extension trait for http::response::Builder objects
Functions§
- get
- Shortcut method to quickly make a
GETrequest.
Type Aliases§
- Result
- A
Resultalias where theErrcase isreqwest::Error.