Wrapping axios within the HttpClient class using TypeScript

Damiano Fusco
Aug 3, 2020 · 4 min read

We often start using third-arty libraries like axios directly in our code. There is nothing wrong about this. However, in a world of ever changing libraries, packages, versions, etc. using these libraries API directly might lead to inconsistent code.

A good practice is to create your own abstraction and wrap the calls to the library API into your wrapper. This will allow you to keep code more consistent, and also more easily switch to a different library/package in the future if you will have to. This is because you wrap all the…