logoalt Hacker News

danscantoday at 3:17 AM11 repliesview on HN

Axios, like Express, is something I'm shocked to see used in any modern codebase. I loved both in the 2010s. In JS/TS-land there are much simpler and better options these days. Depending on Axios suggests the devs don't know how to use fetch. I can't think of another reason it would be a necessary dependency


Replies

zarzavattoday at 5:33 AM

> Depending on Axios suggests the devs don't know how to use fetch.

You could equally say that using fetch means that the developers don't know how to use axios.

They do the same thing, except axios does it a little better, when it doesn't pwn you.

Axios predates the availability of fetch in node by 2 years, and fetch has never caught up with axios so there was no reason to switch to fetch, unless you need to run on both client and server then of course you use fetch.

show 4 replies
tommy_axletoday at 4:02 AM

I wouldn't go that far. Right tool for the job as always. Axios offers a lot over fetch for all but the simplest use cases plus you get to take advantage of the ecosystem. Need offline, axios-cache-interceptor already exists. Sure you can do all of those things with fetch but you need more to go with it taking you right back to just using axios. Also is no one annoyed that you can't replay fetch like the xhr? Same with express: solves a problem reliably.

Chyzwartoday at 10:11 AM

Because your fetch most likely mishandle errors, lack retries, fail on redirects and is unnecessary verbose for both people and agents.

danpalmertoday at 3:40 AM

If you want a fully built out network layer, with auth, logging, monitoring, policies, etc, then `fetch` doesn't really help. Axios and other libraries provide much more for building that sort of framework.

show 1 reply
azangrutoday at 7:58 AM

> Axios, like Express, is something I'm shocked to see used in any modern codebase

I am totally with you on axios; but why is express shocking, and what do you expect to see in its place? Fastify? Hono? Node:http?

jwilliamstoday at 3:26 AM

I do "just use fetch" nowadays -- but I have to say, axios definitely has better ergonomics than fetch, especially for calling APIs.

show 2 replies
ariwilsontoday at 4:14 AM

What's wrong with Express?

show 1 reply
koolbatoday at 4:31 AM

What’s wrong with express?

chvidtoday at 3:51 AM

ChatGPT in general recommends axios over fetch. (At least it did about 2 months ago)

show 1 reply
dheerajvstoday at 7:57 AM

Annoyingly, fetch does not support progress events and HTML / XML Document parsing, which are both supported by XMLHttpRequest, which Axios is based on.

seanp2k2today at 5:18 AM

jQuery is still useful too. May you never work in heathcare / government / defense where you need to support legacy browsers far past their expiration date.