How to Make Async HTTP Requests with reqwest

Make async HTTP requests in Rust by adding reqwest to Cargo.toml and using await with reqwest::get() inside an async function.

Use the reqwest crate with async/await to make non-blocking HTTP requests. Add reqwest to your Cargo.toml and call reqwest::get() inside an async function, then .await the response and its body.

use reqwest;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::get("https://www.rust-lang.org").await?;
    let body = response.text().await?;
    println!("{body}");
    Ok(())
}
[dependencies]
reqwest = { version = "0.12", features = ["json"] }
tokio = { version = "1", features = ["full"] }