mirror of https://github.com/fafhrd91/actix-web
Improve code in examples
This commit is contained in:
parent
8d6eaae299
commit
62aaf1fc4c
|
@ -10,11 +10,10 @@
|
||||||
//! ## Making a GET request
|
//! ## Making a GET request
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # use actix_rt::System;
|
//! # #[actix_rt::main]
|
||||||
//! #[actix_rt::main]
|
|
||||||
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
||||||
//! let mut client = awc::Client::default();
|
//! 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")
|
//! .header("User-Agent", "Actix-web")
|
||||||
//! .send() // <- Send http request
|
//! .send() // <- Send http request
|
||||||
//! .await?;
|
//! .await?;
|
||||||
|
@ -29,11 +28,10 @@
|
||||||
//! ### Raw body contents
|
//! ### Raw body contents
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # use actix_rt::System;
|
|
||||||
//! # #[actix_rt::main]
|
//! # #[actix_rt::main]
|
||||||
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
||||||
//! let mut client = awc::Client::default();
|
//! 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")
|
//! .send_body("Raw body contents")
|
||||||
//! .await?;
|
//! .await?;
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
|
@ -43,13 +41,12 @@
|
||||||
//! ### Forms
|
//! ### Forms
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # use actix_rt::System;
|
|
||||||
//! # #[actix_rt::main]
|
//! # #[actix_rt::main]
|
||||||
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
||||||
//! let params = [("foo", "bar"), ("baz", "quux")];
|
//! let params = [("foo", "bar"), ("baz", "quux")];
|
||||||
//!
|
//!
|
||||||
//! let mut client = awc::Client::default();
|
//! 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)
|
//! .send_form(¶ms)
|
||||||
//! .await?;
|
//! .await?;
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
|
@ -59,17 +56,16 @@
|
||||||
//! ### JSON
|
//! ### JSON
|
||||||
//!
|
//!
|
||||||
//! ```rust
|
//! ```rust
|
||||||
//! # use std::collections::HashMap;
|
|
||||||
//! # use actix_rt::System;
|
|
||||||
//! # #[actix_rt::main]
|
//! # #[actix_rt::main]
|
||||||
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
//! # async fn main() -> Result<(), awc::error::SendRequestError> {
|
||||||
//! let mut map = HashMap::new();
|
//! let mut request = serde_json::json!({
|
||||||
//! map.insert("lang", "rust");
|
//! "lang": "rust",
|
||||||
//! map.insert("body", "json");
|
//! "body": "json"
|
||||||
|
//! });
|
||||||
//!
|
//!
|
||||||
//! let mut client = awc::Client::default();
|
//! let mut client = awc::Client::default();
|
||||||
//! let response = client.post("http://httpbin.org/post")
|
//! let response = client.post("https://httpbin.org/post")
|
||||||
//! .send_json(&map)
|
//! .send_json(&request)
|
||||||
//! .await?;
|
//! .await?;
|
||||||
//! # Ok(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
|
@ -78,20 +74,19 @@
|
||||||
//! ## WebSocket support
|
//! ## WebSocket support
|
||||||
//!
|
//!
|
||||||
//! ```
|
//! ```
|
||||||
//! # use awc::{Client, ws};
|
|
||||||
//! # #[actix_rt::main]
|
//! # #[actix_rt::main]
|
||||||
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
//! # async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
//! use futures_util::{sink::SinkExt, stream::StreamExt};
|
//! 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")
|
//! .ws("ws://echo.websocket.org")
|
||||||
//! .connect()
|
//! .connect()
|
||||||
//! .await?;
|
//! .await?;
|
||||||
//!
|
//!
|
||||||
//! connection
|
//! connection
|
||||||
//! .send(ws::Message::Text("Echo".to_string()))
|
//! .send(awc::ws::Message::Text("Echo".to_string()))
|
||||||
//! .await?;
|
//! .await?;
|
||||||
//! let response = connection.next().await.unwrap()?;
|
//! 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(())
|
//! # Ok(())
|
||||||
//! # }
|
//! # }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
Loading…
Reference in New Issue