call(back)

Axios or fetch?

Axios or fetch — which do you use, and why?

Answer out loud in under a minute: a definition, one concrete example, and one pitfall or trade-off.

Hints

Hint 1

What does fetch do on a 404 or a 500, and what does Axios add on top?

Solution

Show the approach

Answer

fetch is built in, but it resolves on a 404 or a 500, so check res.ok. It needs AbortSignal.timeout for timeouts. Axios rejects on error statuses, parses JSON and has interceptors, at the cost of a dependency. Its cancel tokens are deprecated in favor of AbortController, which both now share.

Assistant

Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.

Asked at

Similar Problems5