Skip to content

Commit

Permalink
Improve code in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
popzxc committed Sep 9, 2020
1 parent 8d6eaae commit 62aaf1f
Showing 1 changed file with 13 additions and 18 deletions.
31 changes: 13 additions & 18 deletions awc/src/lib.rs
Expand Up @@ -10,11 +10,10 @@
//! ## 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!({
//! "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

0 comments on commit 62aaf1f

Please sign in to comment.