← ClaudeAtlas

real-time-weblisted

Use when implementing real-time features with SSE, WebSocket, or HTMX integration in Lexigram
dbtinoy-/lexigram-framework-skills · ★ 1 · Web & Frontend · score 72
Install: claude install-skill dbtinoy-/lexigram-framework-skills
# Real-Time Web ## Overview Lexigram supports two real-time primitives: SSE (one-way server→client) and WebSocket (bidirectional). Both are class-based handlers registered by decorators. HTMX can consume SSE streams for declarative live updates. ## SSE with HTMX Subclass `AbstractSSEHandler`, decorate the **class** with `@sse_endpoint(path)`, and override `stream(request)` as an async generator yielding event dicts: ```python from lexigram.web.sse import sse_endpoint from lexigram.web.sse.handler import AbstractSSEHandler from starlette.requests import Request @sse_endpoint("/events/{channel}", heartbeat_interval=15) class LiveFeedHandler(AbstractSSEHandler): event_types = ["message"] async def stream(self, request: Request): channel = request.path_params["channel"] async for update in subscribe(channel): # your pub/sub source yield {"event": "message", "data": update} ``` There is no `push()` — each client runs its own generator. To fan out to many clients, read from a shared async queue or pub/sub channel inside `stream()` (the built-in `broadcast()` raises `NotImplementedError`). Override `on_connect`/`on_disconnect` for lifecycle; `max_connections` caps concurrency. HTMX client: ```html <div hx-sse="connect:/events/dashboard swap:message"> <div hx-get="/partials/dashboard" hx-trigger="load">Loading…</div> </div> ``` ## WebSocket Handler `@websocket_handler(path)` decorates the **handler class** (not methods). Subcla