From 0360467e7680344639318150f90c9331ba3303af 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 | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/awc/src/lib.rs b/awc/src/lib.rs index 743adcf9ffe..f0504ef3932 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(()) //! # }