Reputation: 24659
I am using RXJS 6 together with Angular 6 HttpClient and I am trying to execute two http calls sequentially.
I thought of using the tap method as follows:
someMethod(items: Item[]): Observable<Item[]> {
const one = this.http.put<{ items: Item[] }>('urlOne', items);
const two = this.http.put<void>('urlTwo', items);
return one.pipe(
mergeMap((res)=> res.items),
tap(two)
);
}
Is there a better way? If so how?
Upvotes: 1
Views: 136
Reputation: 96891
You can use map
and just ignore the second result:
one.pipe(
mergeMap((res) => two.pipe(
mapTo(res)
),
);
Upvotes: 4