Introduction to Streaming API, expose Server Sent Events using WSO2 API Manager
Channel: WSO2
Date: 03/06/2021

APIs commonly requires a client to send a request to the server to receive new data. This client-server interaction style is common to REST-based APIs. A client must periodically send a request to the API to check for data modifications if it wishes to know when something new is available. This pattern is known as polling. However, polling isn't an ideal solution as it is inefficient, complex, and delivers a poor user experience.

Async APIs is an API interaction style that allows the server to inform the consumer when something has changed. WSO2 API Manager supports Webhook, Websocket, and Server-Sent Events (SSE) protocols to maintain (or at least give the impression) persistence communication channels with receivers, the publisher only initiates the connection and the subsequent communication happens through the channel established initially without needing to re-connect. All these protocols are compatible with HTTP.

Server-Sent Events (SSE) is based on something called Server-Sent DOM Events, which was first implemented in Opera 9. The idea is simple: a browser can subscribe to a stream of events generated by a server, receiving updates whenever a new event occurs. As the economy and users are more and more real-time oriented, you need Server-Sent Events if displaying the last data updates to your users may change their actions. The data itself need not change often, but when it changes, you really want users to know it! SSE is used to display data in real-time on a website. That is when displaying data such as Graphs, Game Scores and etc.