Bring back surf example

pull/33/head
Stjepan Glavina 5 years ago
parent 5dd0ab00a0
commit 62be014edc

@ -35,5 +35,5 @@ slab = "0.4.2"
[dev-dependencies]
femme = "1.1.0"
# surf = { git = "ssh://github.com/yoshuawuyts/surf" }
surf = "1.0.1"
tempdir = "0.3.7"

@ -1,15 +0,0 @@
//! Fetches the HTML contents of the Rust website.
#![feature(async_await)]
use std::error::Error;
use async_std::task;
fn main() -> Result<(), Box<dyn Error + Send + Sync>> {
task::block_on(async {
// let contents = surf::get("https://www.rust-lang.org").recv_string().await?;
// println!("{}", contents);
Ok(())
})
}

@ -0,0 +1,21 @@
//! Creates a web request to the Rust website.
#![feature(async_await)]
use async_std::task;
fn main() -> Result<(), surf::Exception> {
task::block_on(async {
let url = "https://www.rust-lang.org";
let mut response = surf::get(url).await?;
let body = response.body_string().await?;
dbg!(url);
dbg!(response.status());
dbg!(response.version());
dbg!(response.headers());
dbg!(body.len());
Ok(())
})
}
Loading…
Cancel
Save