Angular 2+ introduces HttpClient
which makes an HTTP request and sends them down an RxJS observable. My question is why would I choose to use HttpClient
's API over the standard fetch
for making single HTTP requests?
I'm familiar with RxJS and I understand this chart of "the four fundamental effects".
| one | many
-------------------------------------
sync | T | Iterable<T>
async | Promise<T> | Observable<T>
Http requests are async and return one value. Why should that be a Observable? I understand wanting to compose a stream of events into a stream of HTTP requests but I don't understand why I would want to use a stream of just one HTTP response. Isn't that just like using an array when you only have one value?
Am I missing something? In general, why should I use Angular's HttpClient? Where does fetch fall short?