APIs & Authentication

What is a WebSocket?

A protocol for full-duplex, persistent communication between a browser (or other client) and a server over a single long-lived TCP connection.

WebSocket starts as an HTTP request with an Upgrade: websocket header. The server agrees, the connection stops being HTTP, and from that point both sides can push frames at each other until either disconnects. Compared to HTTP polling, it's faster (no per-message handshake), uses less bandwidth (smaller frames), and supports server-initiated messages naturally.

WebSockets power most real-time browser features: live chat, collaborative editors, financial tickers, multiplayer games, dashboards. The protocol itself is minimal, anything app-specific (auth, message types, ack semantics) is layered on top by libraries like Socket.IO, Pusher, or Phoenix Channels.

For 90% of use cases that "need real-time," WebSocket is the right answer. The cases where it isn't are usually answered by Server-Sent Events (one-way push from server) or webhooks (event-driven, no persistent connection).

FAQ

WebSocket vs HTTP polling?

WebSocket is a single persistent connection both sides can write to. Polling is repeated short HTTP requests. WebSocket scales better and feels more real-time; polling is simpler and works behind any HTTP proxy.

WebSocket vs Server-Sent Events (SSE)?

SSE is one-way (server → client) over plain HTTP, which makes it easier to scale and cache. WebSocket is bidirectional and more flexible but heavier. Use SSE for read-only feeds; WebSocket for interactive apps.

Are WebSockets secure?

They support TLS via the wss:// scheme, which behaves like https:// for the WebSocket protocol. Always use wss:// in production.

Related terms

Ship an agent that actually knows things.

Free tier, 10-minute integration, and the same API powering agents at Mintlify, daily.dev, and Propane. No credit card to start.