Chaining http calls in Angular using observables

Imagine situation in which you want to execute http call only when previous call has finished and returned results that the second http call depends on. For instance you want to send email to the customer only when his data has been updated in the system. One endpoint (microservice) is responsible for customer update, second for sending email. This is quite common architecture nowadays where monolith app has been stripped into lots of microservices.
In angular this is easily achievable with Observable and flat map and it came from rxjs library.

Fully working demo is available in this stackblitz example :

https://abdeveloper-observables-chain.stackblitz.io


Main app component


Service



And as you can see in network activity 2 call has been executed after 1st call finished.



Comments