1
0
Fork 0
mirror of https://github.com/actix/actix-web.git synced 2024-11-20 00:21:07 +00:00
actix-web/examples/client.rs

27 lines
822 B
Rust
Raw Normal View History

2019-03-26 19:31:51 +00:00
use actix_http::Error;
2019-01-29 04:41:09 +00:00
use actix_rt::System;
2019-04-11 03:57:18 +00:00
use futures::{future::lazy, Future};
2019-01-29 04:41:09 +00:00
fn main() -> Result<(), Error> {
std::env::set_var("RUST_LOG", "actix_http=trace");
env_logger::init();
System::new("test").block_on(lazy(|| {
2019-03-26 19:31:51 +00:00
awc::Client::new()
.get("https://www.rust-lang.org/") // <- Create request builder
2019-01-29 04:41:09 +00:00
.header("User-Agent", "Actix-web")
2019-03-26 19:31:51 +00:00
.send() // <- Send http request
2019-01-29 04:41:09 +00:00
.from_err()
2019-04-11 03:57:18 +00:00
.and_then(|mut response| {
2019-01-29 04:41:09 +00:00
// <- server http response
println!("Response: {:?}", response);
// read response body
response
2019-04-11 03:57:18 +00:00
.body()
2019-01-29 04:41:09 +00:00
.from_err()
.map(|body| println!("Downloaded: {:?} bytes", body.len()))
})
}))
}