Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

awc: improve module documentation #1656

Merged
merged 7 commits into from Sep 9, 2020
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 15 additions & 20 deletions awc/src/lib.rs
Expand Up @@ -5,16 +5,15 @@
clippy::needless_doctest_main
)]

//! `awc` is a HTTP/WebSocket Client library implemented atop of `actix` stack.
//! `awc` is a HTTP and WebSocket client library built using the Actix ecosystem.
//!
//! ## Making a GET request
//!
//! ```rust
//! # use actix_rt::System;
//! #[actix_rt::main]
//! # #[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
//! let response = client.get("https://www.rust-lang.org") // <- Create request builder
//! .header("User-Agent", "Actix-web")
//! .send() // <- Send http request
//! .await?;
Expand All @@ -29,11 +28,10 @@
//! ### Raw body contents
//!
//! ```rust
//! # use actix_rt::System;
//! # #[actix_rt::main]
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
//! let mut client = awc::Client::default();
//! let response = client.post("http://httpbin.org/post")
//! let response = client.post("https://httpbin.org/post")
//! .send_body("Raw body contents")
//! .await?;
//! # Ok(())
Expand All @@ -43,13 +41,12 @@
//! ### Forms
//!
//! ```rust
//! # use actix_rt::System;
//! # #[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")
//! let response = client.post("https://httpbin.org/post")
//! .send_form(&params)
//! .await?;
//! # Ok(())
Expand All @@ -59,17 +56,16 @@
//! ### JSON
//!
//! ```rust
//! # use std::collections::HashMap;
//! # use actix_rt::System;
//! # #[actix_rt::main]
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
//! let mut map = HashMap::new();
//! map.insert("lang", "rust");
//! map.insert("body", "json");
//! let mut request = serde_json::json!({
robjtede marked this conversation as resolved.
Show resolved Hide resolved
//! "lang": "rust",
//! "body": "json"
//! });
//!
//! let mut client = awc::Client::default();
//! let response = client.post("http://httpbin.org/post")
//! .send_json(&map)
//! let response = client.post("https://httpbin.org/post")
//! .send_json(&request)
//! .await?;
//! # Ok(())
//! # }
Expand All @@ -78,20 +74,19 @@
//! ## WebSocket support
//!
//! ```
//! # use awc::{Client, ws};
//! # #[actix_rt::main]
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
//! use futures_util::{sink::SinkExt, stream::StreamExt};
//! let (_resp, mut connection) = Client::new()
//! let (_resp, mut connection) = awc::Client::new()
//! .ws("ws://echo.websocket.org")
//! .connect()
//! .await?;
//!
//! connection
//! .send(ws::Message::Text("Echo".to_string()))
//! .send(awc::ws::Message::Text("Echo".to_string()))
//! .await?;
//! let response = connection.next().await.unwrap()?;
//! # assert_eq!(response, ws::Frame::Text("Echo".as_bytes().into()));
//! # assert_eq!(response, awc::ws::Frame::Text("Echo".as_bytes().into()));
//! # Ok(())
//! # }
//! ```
Expand Down Expand Up @@ -125,7 +120,7 @@ pub use self::sender::SendClientRequest;

use self::connect::{Connect, ConnectorWrapper};

/// An asynchronous web Client.
/// An asynchronous HTTP and WebSocket client.
///
/// ## Examples
///
Expand Down