1

I am using RXJS 6 together with Angular 6 HttpClient and I am trying to execute two http calls sequentially.

  • I need to return the result of the first call only.
  • The first call must be issued before the second.

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?

1 Answer 1

4

You can use map and just ignore the second result:

one.pipe(
  mergeMap((res) => two.pipe(
    mapTo(res)
  ),
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks a lot by the way :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.