Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what's the difference between HttpModule and HttpClientModule in Angular2?

Tags:

http

angular

I am new in Angular2 and I am learning to make http calls.

I have found Angular2 has these two modules:

HttpModule from @angular/http

and

HttpClientModule from @angular/common/http

and they both support http calls.

However I don't figure out the difference between them.

Does anyone know about this?

like image 552
Judah Flynn Avatar asked Jul 30 '17 23:07

Judah Flynn


People also ask

What is HttpClientModule?

The HttpClientModule is a service module provided by Angular that allows us to perform HTTP requests and easily manipulate those requests and their responses. It is called a service module because it only instantiates services and does not export any components, directives or pipes.

What is the difference between HttpClient and HttpClientModule in angular?

"HttpClient is an evolution of the existing Angular HTTP API, which exists alongside of it in a separate package...". The tutorial uses HttpModule and angular.io/guide/http uses HttpClientModule and neither explains when one or the other should be used or what version of Angular is needed to use what.

Is HttpClientModule deprecated?

As of Angular 4.3. x and above, HttpClientModule is available. In the future HttpModule with its Http class will be deprecated.

What is the difference between HTTP and 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.


1 Answers

HttpClient is a new API that came with 4.3, it has updated API's with support for progress events, json deserialization by default, Interceptors and many other great features. See more here https://angular.io/guide/http

Http is the older API and will eventually be deprecated.

Since their usage is very similar for basic tasks I would advise using HttpClient since it is the more modern and easy to use alternative.

like image 66
Toxicable Avatar answered Sep 28 '22 09:09

Toxicable