0

How can I achieve the following using RXJS? I have 3 requests each dependant on the previous, and I need all responses in the subscription.

this.httpService.request1(paramsObj).pipe(
    switchMap((response)=>{
        return this.httpService.request2({...response})
    }),
    switchMap((response)=>{
        return this.httpService.request3({...response})
    })
).subscribe(([response1, response2, response3]) => {
   // somehow access all responses here while each response is dependeant on the previous one
})
Tomas Katz
  • 1,653
  • 1
  • 13
  • 27
  • 1
    Does this answer your question? [Return switchMap inner results in an array like forkJoin](https://stackoverflow.com/questions/71323064/return-switchmap-inner-results-in-an-array-like-forkjoin) – Amer Mar 13 '22 at 13:16

1 Answers1

2

You probably have to mannually pass it down like below

this.httpService.request1(paramsObj).pipe(
    switchMap((res1)=>{
        return this.httpService.request2({...res1}).pipe(map(res2=>[res1,res2]))
    }),
    switchMap(([res1,res2)=>{
        return this.httpService.request3({...res2}).pipe(map(res3=>[res1,res2,res3]))
    })
).subscribe(([res1, res2, res3]) => {

})
Fan Cheung
  • 10,745
  • 3
  • 17
  • 39