Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Simple blocking http client with reqwest

  • reqwest
  • blocking
  • get
  • status
cargo add reqwest --features blocking
[package]
name = "simple-http-client"
version = "0.1.0"
edition = "2021"

[dependencies]
reqwest = { version = "0.11.20", features = ["blocking"] }
fn main() {
    let res = match reqwest::blocking::get("https://httpbin.org/ip") {
        Ok(res) => res,
        Err(err) => {
            println!("Error {}", err);
            std::process::exit(1);
        }
    };
    println!("{:?}", res.status());
    println!("{:?}", res);
}