Playground API
DocsStatsBlogStudio
Documentation Tree
Technical BlogFeature Deep Dives
  • Introduction
  • Quickstart
    5 min
  • How It Works
  • Recipes & Cookbooks
  • Platform Comparisons
  • Real-World Showcase
  • Interactive Studio
    Studio
  • GraphiQL IDE
    IDE
  • Session Quotas & Activity
  • Network Chaos Simulator
  • Atomic Sandbox Reset
  • Overview & Models
    Hub
  • Users Resource
  • Posts Resource
  • Comments Resource
  • Todos Resource
  • Custom Collections
    Custom
  • Multipart File Uploads
    Upload
  • Dynamic SVG Avatars
    SVG
  • Image Thumbnails
    CDN
  • Relational Filtering
  • Full-Text Search
  • Dynamic Sorting
  • Offset Pagination
  • Cursor Pagination
    Scroll
  • CSV & Excel Export & Import
    IO
  • Custom Collections
    CRUD
  • Overview & Architecture
    Hub
  • JWT Auth Flow
  • Refresh Token Rotation
    Mutex
  • RBAC Permission Matrix
    Roles
  • Expiry Simulation
  • Clock Skew Drift
  • Password Recovery Loop
  • Dual-Mode Sandboxing
  • GraphiQL IDE
    IDE
  • Relational Queries
  • Stateful Mutations
  • Realtime Subscriptions
  • Overview & Flowcharts
    Hub
  • Hosted Checkout
    Stripe
  • Payment Intents API
  • 3DS Challenge Modal
    Modal
  • Customers Vault
  • Charges & Refunds
  • Test Cards Catalog
  • Overview & Channels
    Hub
  • Virtual Email Mailbox
    Mailtrap
  • Virtual SMS Terminal
    Phone
  • In-App Notifications
  • Message Dispatcher
  • Realtime Studio
    Studio
  • Native WebSocket (/ws)
  • Socket.io Gateway
  • Presence & Echo Bot
  • Server-Sent Events (SSE)
    SSE
  • Analytics Telemetry
  • Webhook Subscriptions
  • HMAC SHA-256 Signatures
  • Delivery Logs
  • Manual Retry Simulator
  • Network Latency Delay
  • HTTP Status Codes
  • Rate-Limit Simulator
    429
  • Flaky Network & Jitter
    Chaos
  • Session Quotas & Activity
  • JSON Snapshots
    JSON
  • Headless CI/CD Testing
    CI
  • Mobile QR Code Sync
  • System Metrics & Health
  • Atomic Sandbox Reset
  • Official TypeScript SDK
  • Multi-Language Generators
  • DevTools Extension
  • OpenAPI 3.1 Spec
    JSON
  • Postman Collection v2.1
  • Bruno Collection
  • Insomnia Workspace
  • TypeScript .d.ts
    .d.ts
  • AI Prompt Rules
    Rules
  • Context Index (llms.txt)
  • Full Schema (llms-full.txt)
  • Manifest (product.json)
  • All Feature Articles
    Blog
  • React CRUD Without Backend
    Deep Dive
  • Why Static APIs Fail
  • Mocking Stateful Auth
  • WebSockets & SSE Guide
Technical Blog
Articles

In-depth articles explaining stateful mock APIs, WebSockets, payments, and frontend resilience.

Read Articles
PreviousPresence & Echo Bot
NextAnalytics Telemetry
Realtime & WebSockets

Server-Sent Events (SSE) Stream

Lightweight, HTTP-based unidirectional streaming. Subscribe to live server notifications, background task updates, and automated heartbeats using the native browser EventSource API over standard HTTP/1.1 or HTTP/2 without custom socket libraries.

/api/v1/stream/notifications?samples=truedisconnected
Auto-emit mock notifications (every 8s):
Keepalive: : ping every 15s
[12:00:00][system]:SSE terminal initialized. Click "Connect SSE Stream" to establish an HTTP persistent event stream.

SSE Protocol Headers Reference

The stream endpoint sends the following HTTP response headers to keep connections persistently open:

HeaderValuePurpose
Content-Typetext/event-streamIdentifies payload as EventSource stream format.
Cache-Controlno-cache, no-transformPrevents intermediate proxies and CDNs from buffering chunks.
Connectionkeep-aliveMaintains persistent long-lived TCP connection.
X-Accel-BufferingnoInstructs Nginx reverse proxies to stream chunks immediately.

Client Integration Code

Production examples for native browser EventSource, React hooks, and cURL:

1
// Client Integration using Native Browser EventSource
2
const streamUrl = '/api/v1/stream/notifications?samples=true';
3
const eventSource = new EventSource(streamUrl, { withCredentials: true });
4
5
// 1. Connection opened
6
eventSource.onopen = () => {
7
console.log('SSE connection established');
8
};
9
10
// 2. Listen for custom typed events
11
eventSource.addEventListener('notification', (event) => {
12
const payload = JSON.parse(event.data);
13
console.log('New notification received:', payload);
14
});
15
16
// 3. Listen for general messages
17
eventSource.onmessage = (event) => {
18
console.log('Message event:', event.data);
19
};
20
21
// 4. Handle errors & auto-reconnect
22
eventSource.onerror = (err) => {
23
console.error('SSE Error:', err);
24
};

Server-Sent Events vs WebSockets

When to choose Server-Sent Events over WebSockets for application architecture:

CapabilityServer-Sent Events (SSE)WebSockets (WS)
Communication DirectionUnidirectional (Server → Client)Full-duplex bidirectional
Transport LayerStandard HTTP/1.1 or HTTP/2TCP upgrade to WebSocket protocol
Automatic ReconnectionNative browser auto-retryCustom application retry required
Firewall / Proxy TraversalSeamless (Standard HTTP GET)Requires WebSocket proxy support