From 62be014edc818c5957705b3b76484cc4e1c5e706 Mon Sep 17 00:00:00 2001 From: Stjepan Glavina Date: Thu, 15 Aug 2019 17:03:39 +0200 Subject: [PATCH] Bring back surf example --- Cargo.toml | 2 +- examples/fetch-html.rs | 15 --------------- examples/surf-web.rs | 21 +++++++++++++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) delete mode 100644 examples/fetch-html.rs create mode 100644 examples/surf-web.rs diff --git a/Cargo.toml b/Cargo.toml index 7891057d..45149ad7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/examples/fetch-html.rs b/examples/fetch-html.rs deleted file mode 100644 index e1482214..00000000 --- a/examples/fetch-html.rs +++ /dev/null @@ -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> { - task::block_on(async { - // let contents = surf::get("https://www.rust-lang.org").recv_string().await?; - // println!("{}", contents); - Ok(()) - }) -} diff --git a/examples/surf-web.rs b/examples/surf-web.rs new file mode 100644 index 00000000..e016b089 --- /dev/null +++ b/examples/surf-web.rs @@ -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(()) + }) +}