Skip to content

Instantly share code, notes, and snippets.

@seanmonstar
Created February 7, 2018 23:36
Show Gist options
  • Save seanmonstar/bb7162533e0fdeb37654ed7e204fac1b to your computer and use it in GitHub Desktop.
Save seanmonstar/bb7162533e0fdeb37654ed7e204fac1b to your computer and use it in GitHub Desktop.
hyper v0.12 client example
extern crate hyper;
extern crate tokio;
use tokio::executor::current_thread;
fn main() {
// uses default Handle, the global loop
let client = hyper::Client::new();
current_thread::run(|_| {
let fut = client.get("https://hyper.rs")
.and_then(|res| {
let (_, body) = res.into_parts();
body.concat()
})
.map(|_bytes| {
// do whatever?
})
.map_err(|e| eprintln!("http error: {}", e));
current_thread::spawn(fut);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment