It's 2025, and Axios has supported fetch since v1.7, making it just another fetch wrapper.
The Axios package is 35.6KB/Gzip 13.5KB—too big as a ...
For further actions, you may consider blocking this person and/or reporting abuse
Why people complicate themselves? The
fetch()function is all you need 99% of the time. 1% might need upload/download progress, and that's about it. Interceptors are the worst monster ever. I immediately reject any wrapper with this concept when I can simply do a data-fetching function of my own in a couple lines of code.This is like saying use Date() instead of momentjs(or any other momentjs variations).
Yes, for simple use cases,
fetchis sufficient, just like usingnew Date(). However, for date parsing, formatting, and validation, we needDate()wrapper libraries such asdayjs,date-fns, ormoment.js.That's why a fetch wrapper is beneficial—whether from the community or one we develop ourselves.
Using
cloc,xioris over 1,700 LOC:How much of this is needed on average?
This is the same story for
axios,ky, etc.Yes, a wrapper is beneficial. Just not these wrappers.
Have a look at this code from xior's README:
This is a response interceptor. Look how evident the anti-pattern is here: The NPM package exchanged, using an IF statement, a non-OK response status for a thrown error. This has forced the above example, which is the consumer's code to invert this: The consumer now has to use the callback, examin the error using another IF, just to do what you should have done in the first place: Branch with
response.okorresponse.status.This is so evident. How come people keep defending what has no defense? This is madness.
Yes, Xior includes typescript types, plugins and many other features, which is why there are so many lines of code. And even more lines with the unit tests if you count the tests/ folder.
The response interceptor example code shows people what properties they can get from the function.
I appreciate your comment on this post and the advice. Sorry that the fetch wrapper is not working for you.
I just counted the LOC in /src using the command
perl ..\cloc-dev.pl .\src.The best NPM packages don't add unnecessary overhead and are focused on solving one problem. The main problem with all popular fetch wrappers is the throw-instead-of-branching anti-pattern, which creates overhead where none should exist. The next big problem is the interceptors, where consumers of the package end up writing more code than if no wrapper was used.
When fetch was introduced it eliminated the need for a library such as axios.
Millions of API calls, oauth, bearer token, various cors requirements, etah, cookies, caching proxies, get, post, patch everything in-between.
Fetch has handled it all.
fetch API works for me, nothing more is needed. The more dependencies the worse the things get. Simply my opinion.
Cool! And That's True, The more dependencies the worse the things get. That's the core idea of this lib with unit tests and keep on core functions.
It's 2025 and still people thinking of using something else and doing comparison 🙄.
I'm a newbie ( 1 year old ), and still knows that no matter of others fetch is all you need.
Trust me, you should be proud to share your work with the public, no matter how funny it looks to others.