Improve awc websocket docs

This commit is contained in:
Igor Aleksanov 2020-09-07 09:56:42 +03:00
parent 9a9d4b182e
commit 0e4e0ab5f9
2 changed files with 31 additions and 1 deletions

View File

@ -193,7 +193,8 @@ impl Client {
self.request(Method::OPTIONS, url)
}
/// Construct WebSockets request.
/// Initialize a WebSockets connection.
/// This method returns a builder structure to establish a WebSocket connection.
pub fn ws<U>(&self, url: U) -> ws::WebsocketsRequest
where
Uri: TryFrom<U>,

View File

@ -1,4 +1,33 @@
//! Websockets client
//!
//! This module contains type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket client.
//! To use `awc::Client`
//!
//! # Example
//!
//! ```
//! use awc::{Client, ws};
//! use futures_util::{sink::SinkExt, stream::StreamExt};
//!
//! #[actix_rt::main]
//! async fn main() {
//! let (_resp, mut connection) = Client::new()
//! .ws("wss://echo.websocket.org")
//! .connect()
//! .await
//! .unwrap();
//!
//! connection
//! .send(ws::Message::Text("Echo".to_string()))
//! .await
//! .unwrap();
//! let response = connection.next().await.unwrap().unwrap();
//!
//! assert_eq!(response, ws::Frame::Text("Echo".as_bytes().into()));
//! }
//! ```
//!
use std::convert::TryFrom;
use std::net::SocketAddr;
use std::rc::Rc;