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;
// don't use `ws://` or `wss://` for the url, but rather `http://` or `https://`
let response = Client::default()
.get("https://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§
- The server’s response to the websocket upgrade request.
- Wrapper for
RequestBuilder
that performs the websocket handshake when sent. - A websocket connection
Enums§
- Errors returned by
reqwest_websocket
- An enum representing the various forms of a WebSocket message.
Traits§
- Trait that extends
reqwest::RequestBuilder
with anupgrade
method.