Omtechguy
Omtechguy

Reputation: 3651

rxjs operator that will make http call but will ignore the data and will not return an observable

I would like to make a HTTP call and get the output as observable (this is the easy part) and then, immediately make another HTTP call and ignore the output.

I can not use switchMap operator because the second HTTP call does not return something useful. it just returns 'Done!' and the first call returns complex JSON that i need.

what I did, and it works, is to subscribe to the inner http call and i would like to know if there is an rxjs operator that i can use instead:

this.dataStorageBaseService.createIdentity(identity)
  .do(() => this.authService.JustSimpleHTTPCall().first().subscribe()).subscribe();       

Is there a RxJS operator that i can use instead of subscribe again to the "JustSimpleHTTPCall"? map would be good but i do not need the data that JustSimpleHTTPCall returns and it will not work together with the output of "createIdentity" that I need to return as observable.

Upvotes: 0

Views: 590

Answers (2)

Miller
Miller

Reputation: 2822

You just need your inner Observable to emit the outer result - this can be done with concat

this.dataStorageBaseService.createIdentity(identity)
  .switchMap(result => this.authService.JustSimpleHTTPCall().concat(Observable.of(result)))
  .subscribe(...);

Upvotes: 1

martin
martin

Reputation: 96949

You could do it like this:

this.dataStorageBaseService.createIdentity(identity)
  .concatMap(result => this.authService.JustSimpleHTTPCall()
    .map(() => result) // ignore the second response and use the first one instead
  )
  .subscribe(...);

Upvotes: 3

Related Questions