Skip to content

Latest commit

 

History

History
23 lines (17 loc) · 593 Bytes

File metadata and controls

23 lines (17 loc) · 593 Bytes

rustapi-ws: The Live Wire

Lens: "The Live Wire" Philosophy: "Real-time, persistent connections made simple."

The WebSocket Extractor

Upgrading an HTTP connection to a WebSocket uses the standard extractor pattern:

async fn ws_handler(
    ws: WebSocket,
) -> impl IntoResponse {
    ws.on_upgrade(handle_socket)
}

Architecture

We recommend an Actor Model for WebSocket state.

  1. Each connection spawns a new async task (the actor).
  2. Use tokio::sync::broadcast channels for global events (like chat rooms).
  3. Use mpsc channels for direct messaging.