Nexanexa
Step 11

Realtime: SSE and WebSocket

connectSSE and connectSocket in @nexa/http wrap the browser's native APIs in reactive signals — no proprietary protocol.

Server-Sent Events

import { connectSSE } from "@nexa/http";

const notifications = connectSSE({ url: "/events" });
// notifications.data.value -> the last message

data is the last message received, parsed as JSON when possible.

WebSocket

import { connectSocket } from "@nexa/http";

const chat = connectSocket({ url: "wss://myapp.com/chat" });
chat.send({ text: "hi" });
// chat.status.value -> "connecting" | "open" | "closed"

status reflects the connection's real lifecycle; send() automatically serializes objects as JSON.