Crate reqwest_websocket

source ·
Expand description

Provides wrappers for reqwest to enable WebSocket connections.


// Extends the `reqwest::RequestBuilder` to allow WebSocket upgrades.
use reqwest_websocket::RequestBuilderExt;

// Creates a GET request, upgrades and sends it.
let response = Client::default()
    .upgrade() // Prepares the WebSocket upgrade.

// 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}")



  • 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.



  • Opens a WebSocket connection at the specified URL.