I have an initial 2 http requests I need to make. The first will respond with an array of numbers. Only after the first request can I make the second http request which returns void. After the second http request, I want to then use the values from the first http request and iterate through them making additional http requests for each item
How can I achieve this?
What I have tried
Attempt 1
obs1$ = of([1, 2, 3]);
obs2$ = of(void 0);
concat(obs1$, obs2$).subscribe({next: data => {}});
- sequential http calls [yes]
but data here was of type number[] | undefined, I am only interested in number[]
Attempt 2
obs1$ = of([1, 2, 3]);
obs2$ = of(void 0);
obs1$.pipe(
first(),
tap(() =>
obs2$
)
)
.subscribe({
next: data => {
data.forEach(item =>
//http POST with item
);
}
});
- sequential http calls [yes]
- data is of the desired type [yes]
All the additional http calls in the subscription doesn’t look great and makes error handling tricky