What is the HTTPClient?

The HTTPClient is a custom service class in Angular accessible from @angular/common/http. The HTTPClient is used to communicate with backend services using HTTP methods such as GET, POST, PUT, PATCH, DELETE, etc. The HTTPClient uses the RxJS library to perform its functions.

What is RxJS?

RxJS is a library used to handle asynchronous requests that return an observable in the process. The observable returned can be subscribed to, allowing it to handle and manipulate the data received. It’s worthy to note that observables can be either cold or hot. An observable is cold when data is created within the observable, and the observable is hot when the data is created outside the observable.

Features of RxJS

Operators

An operator is a function that takes in an observable as an input, performs some operations, and returns a new observable with the original observable still intact. Operators are grouped into different categories, some of which include the following:

  • Creation operators (ajax, bindCallback, bindNodeCallback, defer empty)
  • Join creation operators (combineLatest, concat, forkJoin, merge, partition)
  • Transformation operators (buffer, bufferCount, bufferTime, bufferToggle, bufferWhen, concatMap)
  • Filtering operators (audit, auditTime, debounce, debounceTime, distinct)
  • Error-handling operators (catchError, retry, retryWhen)
  • Utility operators(tap, delay, delayWhen, dematerialize, materialize)

Subscription

A Subscription is an object used to execute an observable. A Subscription manages changes that occur in observables and has a method called unsubscribe(). The unsubscribe() method takes no argument and cancels the resource held by the Subscription.

Get hands-on with 1400+ tech skills courses.