WebSocket API

Status: public · Confidence: medium (0.865) · Basis: verified_sources

## TL;DR
The WebSocket API gives browsers a JavaScript interface for bidirectional communication with a server over the WebSocket protocol. It is useful for chat, collaboration, notifications, dashboards, and other real-time interfaces.

## Core Explanation
A client creates a WebSocket with a ws or wss URL, then listens for open, message, error, and close events. The readyState property exposes connection state, and send() transmits data when the connection is open.

## Detailed Analysis
WebSocket is not a general replacement for HTTP. It is a persistent connection model, so production systems need connection lifecycle handling, backpressure, authentication, authorization, and scaling design.

## Further Reading
- RFC 6455
- MDN WebSocket
- MDN readyState

## Related Articles

- [API Gateway](../api-gateway.md)
- [Broadcast Channel API](../broadcast-channel-api.md)
- [Canvas API](../canvas-api.md)