Rocket/contrib/ws/README.md

36 lines
1022 B
Markdown
Raw Normal View History

# `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-03 23:26:07 +00:00
[crate docs]: https://api.rocket.rs/v0.5/rocket_ws
[ci.svg]: https://github.com/SergioBenitez/Rocket/workflows/CI/badge.svg
[ci]: https://github.com/SergioBenitez/Rocket/actions
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" }
```
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?;
}
}
}
```
See the [crate docs] for full details.