Resta saysWebSockets give a persistent two-way channel for real-time APIs.
Where REST is request/response, a WebSocket stays open so server and client can message each other anytime — chat, live dashboards, multiplayer, collaborative editing. The client opens wss://, then both sides send and listen. It trades HTTP's simplicity and caching for low latency and bidirectionality. Use it only when you genuinely need live two-way data.
Power-ups you unlock
Persistent, bidirectional connection
Real-time: chat, dashboards, multiplayer
wss:// on secure pages
Trades caching/simplicity for low latency
The 401 Bandit attacks — common mistakes
Using WebSockets where SSE or polling suffices
No reconnect strategy
Forgetting scale/state implications of many open sockets
Boss battleName two features that genuinely need WebSockets over REST.
Example code
<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre>REST: ask → answer, then done
WebSocket: open channel, both sides push anytime
use for: chat, live collab, multiplayer</pre></body></html>