WebSocket API is a web technology that facilitates real-time, two-way communication between a user's browser and a server. WebSocket API allows the client and server to send messages independently over a persistent connection.
The WebSocket API establishes a persistent connection between the client and the server through an initial HTTP handshake. Once the connection is upgraded to a WebSocket, both parties can continuously exchange data without the overhead of repeated HTTP requests.
This full-duplex communication channel ensures low latency and efficient data transfer. The API manages events such as opening and closing connections, and receiving messages.
When choosing between the WebSocket API and REST API for your use case, consider the following distinctions: