logoalt Hacker News

zarzavattoday at 5:33 AM4 repliesview on HN

> 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.


Replies

kamranjontoday at 5:48 AM

In what ways has fetch never caught up to axios? I have not encountered a situation where I could not use fetch in the last 5 years so I'm just curious what killer features axios has that are still missing in fetch (I certainly remember using axios many moons ago).

show 2 replies
worbletoday at 10:42 AM

> when it doesn't pwn you.

That's a pretty big asterisk though. Taking on a supply chain risk in exchange for reducing developer friction is not worth it in a lot of situations. Every dependency you take increases your risk of getting pwned (especially when it pulls in it's own dependencies), and you seriously need to consider whether it's worth that when you install it.

Don't get me wrong, sometimes it is; I'm certainly not going to create my own web framework from scratch, but a web request helper? Maybe not so much.

show 1 reply
TranquilMarmottoday at 6:47 AM

I usually reach for ky these days since it's an extremely lightweight wrapper over `fetch` - basically just adds a few niceties

https://github.com/sindresorhus/ky

From the readme:

- Simpler API

- Method shortcuts (ky.post())

- Treats non-2xx status codes as errors (after redirects)

- Retries failed requests

- JSON option

- Timeout support

- Upload and download progress

- Base URL option

- Instances with custom defaults

- Hooks

- Response validation with Standard Schema (Zod, Valibot, etc.)

- TypeScript niceties (e.g., .json() supports generics and defaults to unknown, not any)

Of course, this is only for projects where I have to make a lot of HTTP requests to a lot of different places where these niceties make sense. In most cases, we're usually using a library generated from an OpenAPI specification and fall back to `fetch` only as an escape hatch.

samtrack2019today at 5:37 AM

I compare this to the request and httplib in python, request library is vastly superior in usability but both do the same..