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....