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§
- Bytes
- A cheaply cloneable and sliceable chunk of contiguous memory.
- Upgrade
Response - The server’s response to the
WebSocket
upgrade request. - Upgraded
Request Builder - Wrapper for a
reqwest::RequestBuilder
that performs theWebSocket
handshake when sent. - WebSocket
- A
WebSocket
connection. Implementsfutures_util::Stream
andfutures_util::Sink
.
Enums§
- Close
Code - Status code used to indicate why an endpoint is closing the
WebSocket
connection.1 - Error
- Errors returned by
reqwest_websocket
. - Handshake
Error Non-WebAssembly - Error during
Websocket
handshake. - Message
- A
WebSocket
message, which can be a text string or binary data.
Traits§
- Request
Builder Ext - Trait that extends
reqwest::RequestBuilder
with anupgrade
method.
Functions§
- websocket
- Opens a
WebSocket
connection at the specifiedURL
.