rustapi-ws
Lens: "The Live Wire"
Philosophy: "Real-time, persistent connections made simple."
Real-time bidirectional communication for RustAPI, built on tokio-tungstenite.
The WebSocket Extractor
Upgrading an HTTP connection to a WebSocket uses the standard extractor pattern:
async
Architecture
We recommend an Actor Model for WebSocket state:
- Each connection spawns a new async task (the actor)
- Use
tokio::sync::broadcastchannels for global events (like chat rooms) - Use
mpscchannels for direct messaging
Features
- Auto-Upgrade: Handles the HTTP 101 Switching Protocols handshake
- Channels: Built-in pub/sub for broadcast scenarios (chat rooms)
- Ping/Pong: Automatic heartbeat management
Full Example
use ;
async
async