@angular/common/http

What’s the difference between HTTP and HttpClient?

Angular HTTP vs. HttpClient -
The HttpClient is used to perform HTTP requests and it imported form @angular/common/http.
The HttpClient is more modern and easy to use the alternative of HTTP.

HttpClient is an improved replacement for Http. They expect to deprecate Http in Angular 5 and remove it in a later version.

It's an upgraded version of http from @angular/http module with the following improvements –
1.      Immutable request and response objects
2.      Interceptors allow middleware logic to be inserted into the pipeline
3.      Progress events for both request and response
4.      Typed
5.      Event firing
6.      Synchronous response body access
7.      Support JSON body types and JSON by default and now, no need to be explicitly parsed
8.      Automatic conversion from JSON to an object
9.      Post request verification
10.  A flush based testing framework
11.  Simplified syntax for headers

The example with HttpClient -
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

@Injectable()
export class CustomerService {
 
  //Inject HttpClient into your components or services
  constructor(private http: HttpClient) { }
}

And other example with Http –
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';

@Injectable()
export class CustomerService {
 
  //Inject HttpClient into your components or services
  constructor(private http: Http) { }
}


For more detail kindly refer the link.... 
ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..
My Blogs - https://code-sample.com and https://code-sample.xyz
My Book1 - BEST SELLING ANGULAR BOOK (INCLUDING ALL VERSIONS 2, 4, 5, 6, 7)
My Book2 - ANGULAR 2 INTERVIEW QUESTIONS BOOK - Both Books are Available on WorldWide.

www.code-sample.com/. Powered by Blogger.
^