'Why does Angular httpClient returns an Observable instead of a Promise? [closed]

I made a spring reactive backend which returns Flux<> object. When I call the service with angular httpClient and subscribe to the observable returned. The result is never triggered. So why Observable is returned rather than a Promise if only one response is possible ? I have tried the same with hardcoded nodeJS SSE service. I have the same result, but it work well with an event source. My question might be weird but the Observable wasn't choose by chance, so my understanding is certainly wrong and I want to understand.



Solution 1:[1]

Observables have several advantages compared to promises when making HTTP Requests:

  • Retry failed requests (retry, retryWhen)
  • Cancel unnecessary/stale requests (switchMap, unsubscribe...)
  • Better error handling
  • Easily combine multiple HTTP calls, and have control of how to execute them (eg. one by one, or in parallel).

Solution 2:[2]

Angular httpclient will always return an observable (RXjs) , promise is not available in Angular, it was available in AngularJs, you need to subscribe to the observable

for more info read documentation to read more about Observables check this if you are new to Rxjs check this

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alberto Rivera
Solution 2