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

  1. This was much needed and I was looking for it more than a month now. Thanks for the useful info. Keep up the good work!

    ReplyDelete
  2. Your blog got me to learn a lot,thanks for shearing.

    ReplyDelete
  3. Excellent Content. I enjoy how you present. Continue to impart more information.

    ReplyDelete
  4. Thanks for Sharing an Amazing Blog Post!

    ReplyDelete
  5. ownership drive whatever you want.

    ReplyDelete
  6. ¡Gran artículo! Me ayudó a entender mejor cómo encadenar llamadas HTTP en Angular. Además, si alguien necesita descargar algún apktodo apk mod para probar, recomiendo usar una fuente confiable. ¡Saludos!

    ReplyDelete

Post a Comment