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§
- The server’s response to the
WebSocket
upgrade request. - Wrapper for a
reqwest::RequestBuilder
that performs theWebSocket
handshake when sent.
Enums§
- Status code used to indicate why an endpoint is closing the
WebSocket
connection.1 - Errors returned by
reqwest_websocket
. - Handshake
Error Non-WebAssembly Error duringWebsocket
handshake. - A
WebSocket
message, which can be a text string or binary data.
Traits§
- Trait that extends
reqwest::RequestBuilder
with anupgrade
method.
Functions§
- Opens a
WebSocket
connection at the specifiedURL
.