0

I have a situation where I need to make 4 http requests, which should work in concatenation (one takes the output of the previous as input).

I read about the concatMap operator, but I was wondering about if there was a cleaner way to achieve the result.

Maik Barba
  • 103
  • 1
  • 1
  • 6
  • 4
    `concatMap` _is_ the cleaner way. If part of the requests are independent, you could combine them using `forkJoin`. If not, `concatMap` (or `switchMap` based on the requirement) is the solution. – ruth Oct 15 '20 at 10:59
  • You can [read this article](https://medium.com/better-programming/rxjs-patterns-emerging-from-stackoverflow-asynchronous-api-calls-as-streams-in-the-real-world-ef636c9af19a) for some inspiration around typical uses cases for RxJs and http calls. It is a set of scenarios collected from StackOverflow questions. – Picci Oct 15 '20 at 11:01
  • totally agree , you should check the documentations of these operators , https://www.learnrxjs.io/learn-rxjs/operators/transformation check the difference between , concatMap and switchMap. – Koraxos Oct 15 '20 at 11:02
  • 1
    @Koraxos According to Ben Lesh the main architect behind RxJs ([see this video](https://www.youtube.com/watch?v=Dsku0F4lU3A&list=PLJBWPTwg7fuNKFg5BRXKTvDrEi-45YzSE&index=1&t=46s)) `concatMap` is the operator to use most of the times with http. – Picci Oct 15 '20 at 11:10
  • @Picci, thank you i'll check it later! Also i'v seen the mistake in my comments, i have made an edit. – Koraxos Oct 15 '20 at 11:11
  • Does this answer your question? [How to make a sequence of http requests in Angular 6 using RxJS](https://stackoverflow.com/questions/53560652/how-to-make-a-sequence-of-http-requests-in-angular-6-using-rxjs) – Christopher Peisert Oct 15 '20 at 20:39

0 Answers0