Skip to content

Commit

Permalink
Add documentation to connect_async
Browse files Browse the repository at this point in the history
  • Loading branch information
brendano257 committed Aug 3, 2024
1 parent 8325825 commit 540cbe4
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ use tungstenite::{
use crate::{domain, stream::MaybeTlsStream, Connector, IntoClientRequest, WebSocketStream};

/// Connect to a given URL.
///
/// Accepts any request that implements [`IntoClientRequest`], which is often just `&str`, but can
/// be a variety of types such as `httparse::Request` or [`tungstenite::http::Request`] for more
/// complex uses.
///
/// ```no_run
/// use tungstenite::http::{Method, Request};
/// use tokio_tungstenite::connect_async;
///
/// let request = Request::builder()
/// .uri("wss://api.example.com")
/// .method(Method::GET)
/// .header("Sec-WebSocket-Key", "someUniqueValue")
/// .header("Sec-WebSocket-Version", "13")
/// .header("host", "api.example.com")
/// .header("Connection", "Upgrade")
/// .header("Upgrade", "websocket")
/// .body(())
/// .unwrap();
///
/// let (stream, response) = connect_async(request).await.unwrap();
/// ```
pub async fn connect_async<R>(
request: R,
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), Error>
Expand Down

0 comments on commit 540cbe4

Please sign in to comment.