Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Code shared from the Rust Playground
/*
reqwest = "0.9.18"
tokio = "*"
futures = "*"
*/
use futures::{Future, Stream, future};
use reqwest::r#async::Client;
use tokio::runtime::current_thread::Runtime;
fn fetch(url: &str) -> impl Future<Item=&str, Error=()> {
Client::new()
.get(url)
.send()
.and_then(|res| {
res.into_body()
.concat2()
})
.and_then(move |buf| {
future::ok(::std::str::from_utf8(&buf).unwrap())
})
.map_err(|err| panic!("request error: {}", err))
}
fn main() {
let s = Runtime::new().unwrap().block_on(fetch("http://www.example.com/"));
println!("{:?}", s);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.