2024-01-10 04:00:20 +00:00
|
|
|
# `awc` (Actix Web Client)
|
2019-04-16 17:49:38 +00:00
|
|
|
|
2020-10-30 02:50:53 +00:00
|
|
|
> Async HTTP and WebSocket client library.
|
2019-04-16 17:49:38 +00:00
|
|
|
|
2024-01-10 04:00:20 +00:00
|
|
|
<!-- prettier-ignore-start -->
|
|
|
|
|
2020-10-30 02:50:53 +00:00
|
|
|
[](https://crates.io/crates/awc)
|
2024-02-04 00:32:57 +00:00
|
|
|
[](https://docs.rs/awc/3.4.0)
|
2021-02-10 12:10:03 +00:00
|
|
|

|
2024-02-04 00:32:57 +00:00
|
|
|
[](https://deps.rs/crate/awc/3.4.0)
|
2021-06-26 15:33:36 +00:00
|
|
|
[](https://discord.gg/NWpN5mmg3x)
|
2019-04-16 17:49:38 +00:00
|
|
|
|
2024-01-10 04:00:20 +00:00
|
|
|
<!-- prettier-ignore-end -->
|
|
|
|
|
2024-02-07 03:47:30 +00:00
|
|
|
## Examples
|
2020-10-30 02:50:53 +00:00
|
|
|
|
2024-02-07 03:47:30 +00:00
|
|
|
[Example project using TLS-enabled client →](https://github.com/actix/examples/tree/master/https-tls/awc-https)
|
2019-04-16 17:49:38 +00:00
|
|
|
|
2024-02-07 03:47:30 +00:00
|
|
|
Basic usage:
|
2021-02-28 21:41:07 +00:00
|
|
|
|
2019-04-16 17:49:38 +00:00
|
|
|
```rust
|
|
|
|
use actix_rt::System;
|
|
|
|
use awc::Client;
|
|
|
|
|
|
|
|
fn main() {
|
2021-02-07 01:00:40 +00:00
|
|
|
System::new().block_on(async {
|
2020-11-04 22:20:01 +00:00
|
|
|
let client = Client::default();
|
|
|
|
|
|
|
|
let res = client
|
|
|
|
.get("http://www.rust-lang.org") // <- Create request builder
|
2021-03-15 10:59:42 +00:00
|
|
|
.insert_header(("User-Agent", "Actix-web"))
|
2020-11-04 22:20:01 +00:00
|
|
|
.send() // <- Send http request
|
|
|
|
.await;
|
|
|
|
|
|
|
|
println!("Response: {:?}", res); // <- server http response
|
|
|
|
});
|
2019-04-16 17:49:38 +00:00
|
|
|
}
|
|
|
|
```
|