logo

Crate awc[][src]

Expand description

awc is a HTTP and WebSocket client library built on the Actix ecosystem.

Making a GET request

let mut client = awc::Client::default();
let response = client.get("http://www.rust-lang.org") // <- Create request builder
    .insert_header(("User-Agent", "Actix-web"))
    .send()                                            // <- Send http request
    .await?;

 println!("Response: {:?}", response);

Making POST requests

Raw body contents

let mut client = awc::Client::default();
let response = client.post("http://httpbin.org/post")
    .send_body("Raw body contents")
    .await?;

Forms

let params = [("foo", "bar"), ("baz", "quux")];

let mut client = awc::Client::default();
let response = client.post("http://httpbin.org/post")
    .send_form(&params)
    .await?;

JSON

let request = serde_json::json!({
    "lang": "rust",
    "body": "json"
});

let mut client = awc::Client::default();
let response = client.post("http://httpbin.org/post")
    .send_json(&request)
    .await?;

Response Compression

All official and common content encoding codecs are supported, optionally.

The Accept-Encoding header will automatically be populated with enabled codecs and added to outgoing requests, allowing servers to select their Content-Encoding accordingly.

Feature flags enable these codecs according to the table below. By default, all compress-* features are enabled.

FeatureCodecs
compress-brotlibrotli
compress-gzipgzip, deflate
compress-zstdzstd

WebSocket support

use futures_util::{sink::SinkExt, stream::StreamExt};
let (_resp, mut connection) = awc::Client::new()
    .ws("ws://echo.websocket.org")
    .connect()
    .await?;

connection
    .send(awc::ws::Message::Text("Echo".into()))
    .await?;
let response = connection.next().await.unwrap()?;

Re-exports

pub use cookie;

Modules

Traits and structures to aid consuming and writing HTTP payloads.

HTTP client errors

Various HTTP related types.

Test helpers for actix http client to use during testing.

Websockets client

Structs

An asynchronous HTTP and WebSocket client.

An HTTP Client builder

An HTTP Client request builder

Client Response

Manages HTTP client network connectivity.

FrozenClientRequest struct represents cloneable client request.

Builder that allows to modify extra headers.

A Future that reads a body stream, parses JSON, resolving to a deserialized T.

A Future that reads a body stream, resolving as Bytes.

Enums

Future that sends request’s payload and resolves to a server response.

Type Definitions