Most front-end applications use either XMLHttpRequest interface or the fetch() API to communicate with backend services over HTTP protocol. For the same purpose, Angular provides a simplified client HTTP API known as HttpClient. This is based on top of XMLHttpRequest interface. This HttpClient is available in the @angular/common/http package, which you can import in your root module as follows:
- import { HttpClientModule } from '@angular/common/http';
Following are some of the crucial advantages of HttpClient:
- HttpClient contains testability features.
- It provides typed request and response objects.
- It can intercept requests and responses.
- It supports Observalbe APIs.
- HttpClient also supports streamlined error handling.