Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve awc websocket docs #1654

Merged
merged 3 commits into from Sep 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 WebSockets connection.
popzxc marked this conversation as resolved.
Show resolved Hide resolved
/// This method returns a builder structure to establish a WebSocket connection.
popzxc marked this conversation as resolved.
Show resolved Hide resolved
pub fn ws<U>(&self, url: U) -> ws::WebsocketsRequest
where
Uri: TryFrom<U>,
Expand Down
29 changes: 29 additions & 0 deletions awc/src/ws.rs
@@ -1,4 +1,33 @@
//! Websockets client
//!
//! This module contains type definitions required to use [`awc::Client`](../struct.Client.html) as a WebSocket client.
popzxc marked this conversation as resolved.
Show resolved Hide resolved
//! To use `awc::Client`
popzxc marked this conversation as resolved.
Show resolved Hide resolved
//!
//! # 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()));
//! }
//! ```
//!
popzxc marked this conversation as resolved.
Show resolved Hide resolved

use std::convert::TryFrom;
use std::net::SocketAddr;
use std::rc::Rc;
Expand Down