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;

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

// Turns 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? {
    if let Message::Text(text) = message {
        println!("received: {text}")
    }
}

Structs§

Enums§

  • Status code used to indicate why an endpoint is closing the WebSocket connection.1
  • Errors returned by reqwest_websocket.
  • HandshakeErrorNon-WebAssembly
    Error during Websocket handshake.
  • A WebSocket message, which can be a text string or binary data.

Traits§

Functions§

  • Opens a WebSocket connection at the specified URL.