forked from mirror/async-std
Bring back surf example
This commit is contained in:
parent
5dd0ab00a0
commit
62be014edc
3 changed files with 22 additions and 16 deletions
|
@ -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(())
|
||||
})
|
||||
}
|
21
examples/surf-web.rs
Normal file
21
examples/surf-web.rs
Normal file
|
@ -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…
Reference in a new issue