Skip to content

Commit

Permalink
Improve awc websocket docs (#1654)
Browse files Browse the repository at this point in the history
Co-authored-by: Rob Ede <robjtede@icloud.com>
  • Loading branch information
popzxc and robjtede committed Sep 7, 2020
1 parent 9a9d4b1 commit c54d73e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
3 changes: 2 additions & 1 deletion awc/src/lib.rs
Expand Up @@ -193,7 +193,8 @@ impl Client {
self.request(Method::OPTIONS, url)
}

/// Construct WebSockets request.
/// Initialize a WebSocket connection.
/// Returns a WebSocket connection builder.
pub fn ws<U>(&self, url: U) -> ws::WebsocketsRequest
where
Uri: TryFrom<U>,
Expand Down
27 changes: 27 additions & 0 deletions awc/src/ws.rs
@@ -1,4 +1,31 @@
//! Websockets client
//!
//! Type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket 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("ws://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;
Expand Down

0 comments on commit c54d73e

Please sign in to comment.