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
PreviousRealtime Studio
NextSocket.io Gateway
Realtime & WebSockets

Native WebSocket Server (/ws)

Connect to the native browser WebSocket server at /ws. Features room multiplexing, peer-to-peer event broadcasts, typing indicators, and an automated @bot assistant simulator without external socket dependencies.

Realtime WebSocket PubSub & SSE Fallback Architecture
Realtime Protocol
Playground API Modern Realtime WebSocket and SSE Workflow Diagram
Click to expand full architecture
Full-duplex bidirectional event bus: Connection upgrade, channel subscription, presence echo bots, and HTTP SSE fallback.Interactive High-Resolution Flowchart
1HTTP 101 Upgrade

WebSocket Handshake

Client establishes persistent ws:// or wss:// connection passing session identity.

2Multiplexing

Channel PubSub & Bots

Subscribe to rooms (#general, #support) with automated AI bot responses.

3SSE Resilient

SSE Fallback Stream

Server-Sent Events fallback for environments blocking persistent WebSocket frames.

ws://localhost:3001/wsdisconnected
Quick Payloads:
[12:00:00]System:WebSocket client ready. Click "Connect Live WS" to establish a persistent full-duplex session.

WebSocket Protocol Frame Specification

The Playground WebSocket gateway parses standardized JSON envelope payloads:

Frame TypeDirectionPayload ExampleDescription
joinClient → Server{"type":"join","room":"general"}Subscribes socket to a specific channel (e.g. general, support, custom).
chatClient → Server{"type":"chat","text":"Hello"}Broadcasts a chat message to all peers in the current active room.
typingBidirectional{"type":"typing","isTyping":true}Emits keystroke typing bubble to room peers without persisting to database.
messageServer → Client{"type":"message","id":"msg-..","text":".."}Inbound server broadcast dispatched to subscribers with timestamp and sender ID.

Client Integration Code

Production-grade integration patterns for Vanilla JS and React / Next.js hooks:

1
// Native WebSocket Connection (Vanilla JavaScript)
2
const wsUrl = 'ws://localhost:3001/ws';
3
const ws = new WebSocket(wsUrl);
4
5
ws.onopen = () => {
6
console.log('Connected to Playground API WebSocket server');
7
8
// 1. Join room
9
ws.send(JSON.stringify({ type: 'join', room: 'general' }));
10
11
// 2. Send public message
12
ws.send(JSON.stringify({ type: 'chat', text: 'Hello from client!' }));
13
};
14
15
ws.onmessage = (event) => {
16
const frame = JSON.parse(event.data);
17
console.log('Received frame:', frame);
18
};
19
20
ws.onclose = (event) => {
21
console.warn('Disconnected:', event.reason);
22
};