Understanding HTTP polling
HTTP polling is one of the most common techniques to keep your data fresh by fetching the data in regular intervals. By doing so, we can get real time updates from a server, monitor the progress of a long-running tasks, or check for frequent data changes. This is a way to simulate a real-time connection with a server over HTTP, which is a stateless protocol.
How to do it…
In this recipe, we are going to explore a reactive approach to the standard HTTP polling, as well as long polling by building a small cooking recipe app. First, we will load a list of recipes from the mocked BE (using MSW) and show them in the list. Then, we will implement a polling mechanism to check continuously whether there are new recipe data to refresh the list with new data.
Step 1 – Standard HTTP polling
In our http-polling.service.ts
, based on a configurable interval, we set the timer
for that interval. After each of these intervals, we will send a...