Make the async Client default (#626)

The previously default Client is moved to `reqwest::blocking`, while the
async client becomes the main API.

Closes #622
This commit is contained in:
Sean McArthur
2019-09-09 17:20:51 -07:00
committed by GitHub
parent 5fb04356fc
commit 87a09322d6
30 changed files with 1110 additions and 1066 deletions

View File

@@ -1,19 +1,17 @@
//! `cargo run --example simple`
#![deny(warnings)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
env_logger::init();
println!("GET https://www.rust-lang.org");
let mut res = reqwest::get("https://www.rust-lang.org/")?;
#[tokio::main]
async fn main() -> Result<(), reqwest::Error> {
let mut res = reqwest::Client::new()
.get("https://hyper.rs")
.send()
.await?;
println!("Status: {}", res.status());
println!("Headers:\n{:?}", res.headers());
// copy the response body directly to stdout
res.copy_to(&mut std::io::stdout())?;
let body = res.text().await?;
println!("Body:\n\n{}", body);
println!("\n\nDone.");
Ok(())
}