From 62aaf1fc4cd7f04ba0c14f4969c733e15ce545da Mon Sep 17 00:00:00 2001 From: Igor Aleksanov Date: Wed, 9 Sep 2020 14:07:37 +0300 Subject: [PATCH] Improve code in examples --- awc/src/lib.rs | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 743adcf9ffe..80a0bcab2c4 100644 --- a/awc/src/lib.rs +++ b/awc/src/lib.rs @@ -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?; @@ -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(()) @@ -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(¶ms) //! .await?; //! # Ok(()) @@ -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(()) //! # } @@ -78,20 +74,19 @@ //! ## WebSocket support //! //! ``` -//! # use awc::{Client, ws}; //! # #[actix_rt::main] //! # async fn main() -> Result<(), Box> { //! 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(()) //! # } //! ```