Crate reqwest_websocket

source ·
Expand description

Provides wrappers for reqwest to enable websocket connections.

§Example

// Extends the reqwest::RequestBuilder to allow websocket upgrades
use reqwest_websocket::RequestBuilderExt;

// create a GET request, upgrade it and send it.
let response = Client::default()
    .get("wss://echo.websocket.org/")
    .upgrade() // prepares the websocket upgrade.
    .send()
    .await?;

// turn the response into a websocket stream
let mut websocket = response.into_websocket().await?;

// the websocket implements `Sink<Message>`.
websocket.send(Message::Text("Hello, World".into())).await?;

// the websocket is also a `TryStream` over `Message`s.
while let Some(message) = websocket.try_next().await? {
    match message {
        Message::Text(text) => println!("{text}"),
        _ => {}
    }
}

Structs§

Enums§

  • Errors returned by reqwest_websocket
  • Error during Websocket handshake
  • A websocket message, which can be a text string or binary data.

Traits§

Functions§

  • Opens a websocket at the specified URL.