0
Challenge · 50Routing & Data
Axios
Ecoused in ~70% of apps
Every fetch call repeats the same chore: check res.ok, parse res.json(), attach the auth header. Axios is a thin HTTP client that does all three for you — and lets you wire cross-cutting logic (tokens, logging, retries) in ONE place with interceptors.
Core idea. Axios is a promise-based HTTP client wrapping XMLHttpRequest/fetch: it auto-parses JSON into res.data, rejects automatically on non-2xx, and supports reusable instances with a baseURL plus request/response interceptors. In 2026 fetch is enough for most apps; axios buys convenience, not capability.
poke it, drag it,
try to break it
try to break it
no slides here.
you drive.
you drive.
Playground, this isn't a screenshot
SERVER REPLIES
GET /api/usersame request, two clients
fetchbuilt-in
const headers = { Authorization: `Bearer ${token}` }
const res = await fetch(url, { headers })
if (!res.ok) throw new Error(res.status)
const data = await res.json()
resolves
data = { name: 'Aria' }
axios~13kb dep
// interceptor auto-adds Authorization
const res = await axios.get(url)
// 2xx → resolves
const data = res.data
resolves
res.data already parsed
An axios interceptor injects the auth header in ONE place; with fetch you remember it on every call.
axios trades a dependency for convenience: auto-JSON, auto-throw on non-2xx, and interceptors. fetch does the same job with a little more wiring.
↑ play a little first, then dig in