A match against the old standard

The new HttpClient was introduced in July 2017 as an improved version of the former Angular HTTP client API, also known as @angular/http, or simply HTTP. Instead of replacing the old version in the @angular/http package, the Angular development team has put the new classes in a separate package--@angular/common/http. They chose to do that to preserve the backward-compatibility with the existing code bases and also to ensure a slow, yet steady migration to the new API.

Those who used the old Angular HTTP service class at least once will most likely remember its main limitations:

  • JSON was not enabled by default, forcing the developers to explicitly set it within the request Headers--and JSON.parse/stringify the data--when working with RESTful APIs.
  • There was no easy way to access the HTTP request/response pipeline, thus preventing the developer from intercepting or altering the request and/or response calls after they were issued or received, by using some ugly and pattern-breaking hacks. As a matter of fact, extensions and wrapper classes were basically the only way to customize the service, at least on a global scope.
  • There was no native strong-typing for request and response objects (although we can cast JSON-as-interfaces as a workaround).

The great news is that the new HttpClient does all of this and much more; other features include testability support and better error handling via APIs entirely based on Observables.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.218.97.75