Function tokio_tungstenite::connect_async

source ยท
pub async fn connect_async<R>(
    request: R,
) -> Result<(WebSocketStream<MaybeTlsStream<TcpStream>>, Response), Error>
Expand description

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.


use tungstenite::http::{Method, Request};
use tokio_tungstenite::connect_async;

let mut request = "wss://api.example.com".into_client_request().unwrap();
request.headers_mut().insert("api-key", "42".parse().unwrap());

let (stream, response) = connect_async(request).await.unwrap();