How to Make HTTP Requests in Rust (reqwest)

Make HTTP requests in Rust by adding the reqwest crate and using async/await to fetch data from URLs.

Use the reqwest crate with async/await to send HTTP requests. Add reqwest to your Cargo.toml, then import the client and use get() to fetch data asynchronously.

use reqwest;

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

Add these to your Cargo.toml:

[dependencies]
reqwest = { version = "0.12", features = ["json"] }
tokio = { version = "1", features = ["full"] }