I'm learning Angular, Spring Boot and Hibernate at the moment and I found a good tutorial on that. But I have a problem where I can't find the answer. There are occasions where I have multiple REST calls to do and I can't combine them in a single one, e.g. I have to increment an amount in one call and to decrement the amount of another object in another (can also be on different servers/applications).
The solution I know so far is to call the API, subscribe it and if it succeeds to start the other API call. I could react on both results if there is an error like:
this.sourceService.decrement( { body: this.decrementRequest }).subscribe( { next: (): void => { this.targetService( { body: this.incrementRequest }).subscribe( { next: (): void => { this.router.navigate(['/transfer/done']); }, error: (err) => { this.router.navigate(['/transfer/done']); } }); }, error: (err) => { this.router.navigate(['/transfer/done']); } });
But when I do it this way, having an error in the targetService would lead to wrong data because the sourceService already did its job. It is also not advisable to call the sourceService again with a kind of "undo" because you don't know, if the failure also occures in this call.
So does anybody has a hint where I can find a tutorial explaining a pattern or methods/interfaces that I can use to make transactional REST calls?
Thanks in advance
Parascus