Skip to content

Fetch

Easy — everyone uses thisFrontend

ELI5 — The Vibe Check

Fetch is the modern, built-in JavaScript way to make HTTP requests to APIs. You tell it a URL, it goes and gets the data, and you handle the response. It replaced the older, uglier XMLHttpRequest. It returns a Promise, so you can use async/await with it.

Real Talk

The Fetch API is a modern browser API for making HTTP requests. It returns a Promise that resolves to a Response object. Unlike XMLHttpRequest, Fetch uses Promises natively, supports streaming, and provides a cleaner interface. Note: Fetch does not reject on HTTP error status codes (4xx/5xx) — you must check response.ok manually.

Show Me The Code

// Basic GET request
const res = await fetch('https://api.example.com/users')
if (!res.ok) throw new Error(`HTTP error: ${res.status}`)
const users = await res.json()

// POST with JSON body
const res2 = await fetch('/api/users', {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ name: 'Alice' })
})

When You'll Hear This

Fetch won't throw on 404 — always check response.ok.,Use AbortController to cancel fetch requests.,Fetch is now available in Node.js 18+ natively.

Made with passive-aggressive love by manoga.digital. Powered by Claude.