fetch vs axios vs request-promise vs superagent
Which HTTP Client should we use for frontend 🤔
There are lots of ways to make API call from frontend project. Yaa we love them all, but you use only one. So let's decide look which is great.
Let look on which package is download most.
Npm trends say whatwg-fetch (fetch polyfill) is most downloaded one, this might because of Create React App and many other bootstrap project setup includes a fetch polyfill out of the box for developers, and the second position we have axios.
Cost Of Module
For frontend projects, bundle size matters.
And here again fetch polyfill is the winner, and we can eliminate request-promise, who wants to add 66kb in the bundle just to make API calls. 🙄
It looks like axios support all features .🥰
fetch() is the new standard. It’s already supported in Chrome and Firefox — so if don’t need IE or Safari support you can use it today without any library at all. I suggest you start here.
If you need support for more browsers Use GitHub’s Fetch polyfill. You get to use the new standard now, and eventually, you can delete the polyfill library when more browsers support Fetch, so free of import cost in future.
If Developer Experience matters Use axios, its have very nice documentation, easy to use and learning curve is not too steep.