2020-10-30 03:50:53 +01:00
|
|
|
//! `awc` is a HTTP and WebSocket client library built on the Actix ecosystem.
|
2020-09-09 15:24:12 +02:00
|
|
|
//!
|
2021-06-19 21:23:06 +02:00
|
|
|
//! # Making a GET request
|
2021-01-08 13:00:58 +01:00
|
|
|
//! ```no_run
|
2020-09-09 15:24:12 +02:00
|
|
|
//! # #[actix_rt::main]
|
|
|
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
|
|
|
//! let mut client = awc::Client::default();
|
|
|
|
//! let response = client.get("http://www.rust-lang.org") // <- Create request builder
|
2021-01-15 03:11:10 +01:00
|
|
|
//! .insert_header(("User-Agent", "Actix-web"))
|
2020-09-09 15:24:12 +02:00
|
|
|
//! .send() // <- Send http request
|
|
|
|
//! .await?;
|
|
|
|
//!
|
|
|
|
//! println!("Response: {:?}", response);
|
|
|
|
//! # Ok(())
|
|
|
|
//! # }
|
|
|
|
//! ```
|
|
|
|
//!
|
2021-06-19 21:23:06 +02:00
|
|
|
//! # Making POST requests
|
|
|
|
//! ## Raw body contents
|
2021-01-08 13:00:58 +01:00
|
|
|
//! ```no_run
|
2020-09-09 15:24:12 +02:00
|
|
|
//! # #[actix_rt::main]
|
|
|
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
|
|
|
//! let mut client = awc::Client::default();
|
|
|
|
//! let response = client.post("http://httpbin.org/post")
|
|
|
|
//! .send_body("Raw body contents")
|
|
|
|
//! .await?;
|
|
|
|
//! # Ok(())
|
|
|
|
//! # }
|
|
|
|
//! ```
|
|
|
|
//!
|
2021-06-19 21:23:06 +02:00
|
|
|
//! ## Forms
|
2021-01-08 13:00:58 +01:00
|
|
|
//! ```no_run
|
2020-09-09 15:24:12 +02:00
|
|
|
//! # #[actix_rt::main]
|
|
|
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
|
|
|
//! let params = [("foo", "bar"), ("baz", "quux")];
|
|
|
|
//!
|
|
|
|
//! let mut client = awc::Client::default();
|
|
|
|
//! let response = client.post("http://httpbin.org/post")
|
|
|
|
//! .send_form(¶ms)
|
|
|
|
//! .await?;
|
|
|
|
//! # Ok(())
|
|
|
|
//! # }
|
|
|
|
//! ```
|
2019-03-27 17:24:55 +01:00
|
|
|
//!
|
2021-06-19 21:23:06 +02:00
|
|
|
//! ## JSON
|
2021-01-08 13:00:58 +01:00
|
|
|
//! ```no_run
|
2020-09-09 15:24:12 +02:00
|
|
|
//! # #[actix_rt::main]
|
|
|
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
|
|
|
//! let request = serde_json::json!({
|
|
|
|
//! "lang": "rust",
|
|
|
|
//! "body": "json"
|
|
|
|
//! });
|
2019-11-26 06:25:50 +01:00
|
|
|
//!
|
2020-09-09 15:24:12 +02:00
|
|
|
//! let mut client = awc::Client::default();
|
|
|
|
//! let response = client.post("http://httpbin.org/post")
|
|
|
|
//! .send_json(&request)
|
|
|
|
//! .await?;
|
|
|
|
//! # Ok(())
|
|
|
|
//! # }
|
2019-03-27 17:24:55 +01:00
|
|
|
//! ```
|
2020-09-09 15:24:12 +02:00
|
|
|
//!
|
2021-06-19 21:23:06 +02:00
|
|
|
//! # Response Compression
|
|
|
|
//! All [official][iana-encodings] and common content encoding codecs are supported, optionally.
|
2020-09-09 15:24:12 +02:00
|
|
|
//!
|
2021-06-19 21:23:06 +02:00
|
|
|
//! 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.
|
|
|
|
//!
|
|
|
|
//! | Feature | Codecs |
|
|
|
|
//! | ----------------- | ------------- |
|
|
|
|
//! | `compress-brotli` | brotli |
|
|
|
|
//! | `compress-gzip` | gzip, deflate |
|
|
|
|
//! | `compress-zstd` | zstd |
|
|
|
|
//!
|
|
|
|
//! [iana-encodings]: https://www.iana.org/assignments/http-parameters/http-parameters.xhtml#content-coding
|
|
|
|
//!
|
|
|
|
//! # WebSocket support
|
2021-01-08 13:00:58 +01:00
|
|
|
//! ```no_run
|
2020-09-09 15:24:12 +02:00
|
|
|
//! # #[actix_rt::main]
|
|
|
|
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
|
|
//! use futures_util::{sink::SinkExt, stream::StreamExt};
|
|
|
|
//! let (_resp, mut connection) = awc::Client::new()
|
|
|
|
//! .ws("ws://echo.websocket.org")
|
|
|
|
//! .connect()
|
|
|
|
//! .await?;
|
|
|
|
//!
|
|
|
|
//! connection
|
2021-01-04 12:27:32 +01:00
|
|
|
//! .send(awc::ws::Message::Text("Echo".into()))
|
2020-09-09 15:24:12 +02:00
|
|
|
//! .await?;
|
|
|
|
//! let response = connection.next().await.unwrap()?;
|
|
|
|
//! # assert_eq!(response, awc::ws::Frame::Text("Echo".as_bytes().into()));
|
|
|
|
//! # Ok(())
|
|
|
|
//! # }
|
|
|
|
//! ```
|
|
|
|
|
2021-12-08 07:09:56 +01:00
|
|
|
#![deny(rust_2018_idioms, nonstandard_style)]
|
|
|
|
#![warn(future_incompatible)]
|
2020-10-30 03:50:53 +01:00
|
|
|
#![allow(
|
|
|
|
clippy::type_complexity,
|
|
|
|
clippy::borrow_interior_mutable_const,
|
|
|
|
clippy::needless_doctest_main
|
|
|
|
)]
|
|
|
|
#![doc(html_logo_url = "https://actix.rs/img/logo.png")]
|
|
|
|
#![doc(html_favicon_url = "https://actix.rs/favicon.ico")]
|
|
|
|
|
2021-12-04 20:40:47 +01:00
|
|
|
mod any_body;
|
2019-03-26 05:58:01 +01:00
|
|
|
mod builder;
|
2021-10-26 01:37:40 +02:00
|
|
|
mod client;
|
2019-03-26 05:58:01 +01:00
|
|
|
mod connect;
|
2019-03-28 02:53:19 +01:00
|
|
|
pub mod error;
|
2019-09-12 06:40:56 +02:00
|
|
|
mod frozen;
|
2021-02-28 19:17:08 +01:00
|
|
|
pub mod middleware;
|
2019-03-26 05:58:01 +01:00
|
|
|
mod request;
|
2021-12-25 03:33:37 +01:00
|
|
|
mod responses;
|
2019-09-12 06:40:56 +02:00
|
|
|
mod sender;
|
2019-03-27 05:54:57 +01:00
|
|
|
pub mod test;
|
2019-03-29 21:49:21 +01:00
|
|
|
pub mod ws;
|
2019-03-26 05:58:01 +01:00
|
|
|
|
2021-12-05 15:37:20 +01:00
|
|
|
// TODO: hmmmmmm
|
|
|
|
pub use actix_http as http;
|
2021-10-26 01:37:40 +02:00
|
|
|
#[cfg(feature = "cookies")]
|
|
|
|
pub use cookie;
|
|
|
|
|
2019-03-26 05:58:01 +01:00
|
|
|
pub use self::builder::ClientBuilder;
|
2021-12-25 03:23:22 +01:00
|
|
|
pub use self::client::{Client, Connector};
|
2021-03-18 18:53:22 +01:00
|
|
|
pub use self::connect::{BoxConnectorService, BoxedSocket, ConnectRequest, ConnectResponse};
|
2019-09-12 06:40:56 +02:00
|
|
|
pub use self::frozen::{FrozenClientRequest, FrozenSendBuilder};
|
2019-03-26 05:58:01 +01:00
|
|
|
pub use self::request::ClientRequest;
|
2021-12-25 03:33:37 +01:00
|
|
|
#[allow(deprecated)]
|
|
|
|
pub use self::responses::{ClientResponse, JsonBody, MessageBody, ResponseBody};
|
2019-09-12 06:40:56 +02:00
|
|
|
pub use self::sender::SendClientRequest;
|
2019-03-26 05:58:01 +01:00
|
|
|
|
2021-12-04 20:40:47 +01:00
|
|
|
pub(crate) type BoxError = Box<dyn std::error::Error>;
|