2023-04-01 22:02:24 +00:00
|
|
|
# `ws` [![ci.svg]][ci] [![crates.io]][crate] [![docs.svg]][crate docs]
|
|
|
|
|
|
|
|
[crates.io]: https://img.shields.io/crates/v/rocket_ws.svg
|
|
|
|
[crate]: https://crates.io/crates/rocket_ws
|
|
|
|
[docs.svg]: https://img.shields.io/badge/web-master-red.svg?style=flat&label=docs&colorB=d33847
|
2023-11-18 10:30:50 +00:00
|
|
|
[crate docs]: https://api.rocket.rs/master/rocket_ws
|
2023-11-21 15:29:44 +00:00
|
|
|
[ci.svg]: https://github.com/rwf2/Rocket/workflows/CI/badge.svg
|
|
|
|
[ci]: https://github.com/rwf2/Rocket/actions
|
2023-04-01 22:02:24 +00:00
|
|
|
|
|
|
|
This crate provides WebSocket support for Rocket via integration with Rocket's
|
|
|
|
[connection upgrades] API.
|
|
|
|
|
|
|
|
# Usage
|
|
|
|
|
|
|
|
1. Depend on `rocket_ws`, renamed here to `ws`:
|
|
|
|
|
|
|
|
```toml
|
|
|
|
[dependencies]
|
2023-11-03 23:26:07 +00:00
|
|
|
ws = { package = "rocket_ws", version = "0.1.0" }
|
2023-04-01 22:02:24 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
2. Use it!
|
|
|
|
|
2023-04-04 22:37:22 +00:00
|
|
|
```rust
|
|
|
|
#[get("/echo")]
|
|
|
|
fn echo_stream(ws: ws::WebSocket) -> ws::Stream!['static] {
|
2023-08-14 22:46:21 +00:00
|
|
|
ws::Stream! { ws =>
|
2023-04-04 22:37:22 +00:00
|
|
|
for await message in ws {
|
|
|
|
yield message?;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
```
|
2023-04-01 22:02:24 +00:00
|
|
|
|
|
|
|
See the [crate docs] for full details.
|