Making two http requests sequentially in angular, rxjs

igor

Currently I have the following request:

      return this.registrationService.registratePerson(data).pipe(
        switchMap(
          res => {
            return this.registrationService.sendPassportScan(this.form.value.passportScanCopyFile, res.AisUserIsn);
          }
        )
      );

The second request makes use of the result obtained in the first one, that's something that I need but the problem with it is that now it returns what comes from the second request (the inner one). Is it possible somehow with the help of rxjs operators to make it return an observable containing fields from the inner request as well as those from the outer one?

In the application the 5th version of rxjs is used.

mbojko

Sure. Something like this:

return this.registrationService.registratePerson(data).pipe(
    switchMap(
        res => forkJoin(
            of(res), 
            this.registrationService.sendPassportScan(/* relevant args */),
        )))

(The resulting stream will contain a 2 element array).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Angular and RxJs combine two http requests

Handling two HTTP requests (Angular + RxJS)

Angular and RxJS - merge two HTTP requests, but emit the outer one instantly

RxJS batch HTTP requests in Angular

RxJS - Combine Two HTTP GET Parallel Requests

Angular 8 RXJS - Make multiple HTTP calls sequentially

Angular RxJS Nested Subscribe with multiple Http Requests

Angular rxjs call http requests in batches with a delay

angular rxjs: handle multiple http requests

Angular5 RXJS recursive http requests

Sending two HTTP Requests one after each other using Angular / RXJS where second request requires the first?

Making HTTP(s) requests between two App Engine projects

Making HTTP requests with Clojure

Karate is making two requests

How to correctly subscribe to a service that is making different HTTP get requests? [Angular]

Angular Service making Http requests to localhost:4200 instead of localhost:8080

Send files over angular Http sequentially (serially) one by one in angular using rxjs concatMap() operator

Angular $http.get sending two requests

Angular Testing - Chained HTTP Requests using rxjs switchMap

Angular and RxJS - merge multiple HTTP requests, but emit the outer one instantly

How to use RxJS to cancel previous HTTP Requests in an Angular Service

Angular/RxJS 6: How to prevent duplicate HTTP requests?

How to make a sequence of http requests in Angular 6 using RxJS

Angular combine and transform multiple http requests with forJoin Rxjs operator

Fire observable sequentially (or parallel) not working, when making http calls angular2

how to run two requests sequentially in jmeter

Asyncio Making HTTP Requests Slower?

Making two requests with android volley

Performing advanced http requests in rxjs