fix awc doc example

This commit is contained in:
fakeshadow 2020-11-05 02:19:41 +08:00
parent 61b65aa64a
commit 2a67211621
1 changed files with 12 additions and 14 deletions

View File

@ -16,23 +16,21 @@
- Minimum Supported Rust Version (MSRV): 1.42.0
## Example
```rust
use actix_rt::System;
use awc::Client;
use futures::future::{Future, lazy};
use actix_web::client::Client;
use actix_web::rt::System;
fn main() {
System::new("test").block_on(lazy(|| {
let mut client = Client::default();
System::new("test").block_on(async {
let client = Client::default();
client.get("http://www.rust-lang.org") // <- Create request builder
.header("User-Agent", "Actix-web")
.send() // <- Send http request
.and_then(|response| { // <- server http response
println!("Response: {:?}", response);
Ok(())
})
}));
let res = client
.get("http://www.rust-lang.org") // <- Create request builder
.header("User-Agent", "Actix-web")
.send() // <- Send http request
.await;
println!("Response: {:?}", res); // <- server http response
});
}
```