HTTP Clients
Recipe | Crates | Categories |
---|---|---|
reqwest | ||
ureq | ||
Build a HTTP Client with hyper |
reqwest
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
⮳ 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
⮳ 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