How to use reqwest crate in Rust HTTP client

Add reqwest to Cargo.toml with rustls-tls feature and use reqwest::get in an async function to fetch HTTP data.

Add reqwest to your Cargo.toml with the rustls-tls feature, then use reqwest::get inside an async function to fetch data.

use reqwest;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    let response = reqwest::get("https://www.rust-lang.org").await?;
    let text = response.text().await?;
    println!("Status: {}", response.status());
    println!("Body: {}", text);
    Ok(())
}

In Cargo.toml, ensure the dependency is configured as:

[dependencies]
reqwest = { version = "0.12", default-features = false, features = ["rustls-tls"] }
tokio = { version = "1", features = ["rt-multi-thread", "macros"] }