[−][src]Crate awc
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 .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(¶ms) .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?;
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".to_string())) .await?; let response = connection.next().await.unwrap()?;
Re-exports
pub use actix_http::cookie; |
Modules
error | Http client errors |
http | Various HTTP related types |
test | Test helpers for actix http client to use during testing. |
ws | Websockets client |
Structs
BoxedSocket | |
Client | An asynchronous HTTP and WebSocket client. |
ClientBuilder | An HTTP Client builder |
ClientRequest | An HTTP Client request builder |
ClientResponse | Client Response |
Connector | Manages http client network connectivity
The |
FrozenClientRequest |
|
FrozenSendBuilder | Builder that allows to modify extra headers. |
JsonBody | Response's payload json parser, it resolves to a deserialized |
MessageBody | Future that resolves to a complete http message body. |
Enums
SendClientRequest | Future that sends request's payload and resolves to a server response. |