0

I'm creating an application in Angular 4 which will be used for placing order for a company. After placing an order, the status of that order is updated in the back-end. But, because the API I'm using to retrieve the status is not updating the status, rather a BPM is updating the status in the API and then my Angular application is getting that status from the API. Since the front-end doesn't know when BPN updates the status in the API, it has to constantly hit the API using something like:

intervalForStatus = setInterval(() => {
  someService.hitEndPoint().subscribe((data) => {
    ......
  });
}, 5000);

But this setInterval will hit the API after every 5 seconds to fetch the status, which created unwanted traffic. Is their a way to know when the value gets updated in the API, so that the front-end can only hit the API when the status is updated?

Aiguo
  • 3,416
  • 7
  • 27
  • 52
  • 2
    You will need a server-to-client communication technology, if you want your frontend to be *notified* on backend changes. Look into socket.io, SingalR and other alternatives. – CozyAzure Aug 16 '17 at 02:16

1 Answers1

0

Your backend should have some form of serve to client communication capability. There are 2 choices for the same

  1. Server Sent Events
  2. Websockets

You can refer to below stackoverflow link to get more insights into the differences of both and you can use one that fits your needs.

SSE vs WS