Angular Update 2 to 4, Migrating from Http to HttpClient

I have a great Angular2 application that is now porting to Angular4 . However, it still uses the Http service.

I understand that Angular4 has an HttpClient which is said to be better than Http . However, I am afraid to change to HttpClient , since it is used in many places and related unit tests.

I would like to know what is the best transition from Http to HttpClient ? What should I consider in terms of code and unit tests?

Another reason I would like to upgrade to HttpClient is to use an interceptor? To do this, you need to change to HttpClient ?

Please inform. Thank you very much in advance.

+5
source share
1 answer

Only my experience.

As I recall, my biggest problem was removing the card in every HTTP call.

Otherwise, you just need to import the HttpClientModule and enter HttpClient instead of Http.

In addition, there are some changes to unit testing. Therefore, if you have unit tests, you have a little more work. With HttpClient unit testing has become much easier. Angular has large documents, so I don't think this will be a big problem. At least for me, I had no problems understanding this new material.

You can check this article for more information: http://brianflove.com/2017/07/21/migrating-to-http-client/ .

+3
source

Source: https://habr.com/ru/post/1271152/


All Articles