Skip to main content

Module ws

Module ws 

Source
Expand description

WebSocket helpers for endpoints that stream events over a persistent connection (e.g. /api/v1/notifications/stream).

Built on tokio_tungstenite with rustls + webpki roots so it works out of the box against TLS deployments. Exposes a futures::Stream of parsed JSON events — callers decide how to handle each one.

§Example

use futures::StreamExt;
use nucel_sdk_api::ws::{NotificationStreamEvent, stream_notifications};

let mut events = stream_notifications("https://nucel.dev", "ghp_token").await?;
while let Some(Ok(ev)) = events.next().await {
    match ev {
        NotificationStreamEvent::Init { unread_count } => {
            println!("connected, {unread_count} unread");
        }
        NotificationStreamEvent::Other(v) => {
            println!("event: {v}");
        }
    }
}

Enums§

NotificationStreamEvent
An event on the notification stream.
WsError
Errors the WebSocket stream can produce.

Functions§

build_ws_url
Turn http(s)://host[:port] + a path into a ws(s)://host[:port]/path?token=....
stream_notifications
Open a WebSocket to /api/v1/notifications/stream and return a stream of parsed events. The token is sent as both an Authorization: Bearer header AND a ?token= query param so the call works against any server config.