fetch() JSON API examples (GET, POST, PUT, DELETE)

Last updated 2026-05-20

Example JSON

Reference JSON payload returned by /users/1 (used in every snippet below).

{
  "id": 1,
  "firstName": "Emily",
  "lastName": "Johnson",
  "email": "[email protected]",
  "username": "emilys",
  "image": "https://jsonexamples.com/image/200?text=User+1",
  "address": {
    "address": "626 Main Street",
    "city": "Phoenix",
    "state": "OK",
    "postalCode": "29920",
    "country": "United States"
  }
}

Request examples

async function getUser(id) {
  const res = await fetch('https://jsonexamples.com/users/' + id);
  if (!res.ok) throw new Error('HTTP ' + res.status);
  return res.json();
}

Try the live endpoint

Click below to call /users/1 from your browser.

GET/users/1
{
  "hint": "Click 'Run' to call the live endpoint"
}

Common variations

AbortController for timeouts

Cancel the request after 5 seconds.

{
  "snippet": "const ac = new AbortController();\nsetTimeout(() => ac.abort(), 5000);\nawait fetch(url, { signal: ac.signal });"
}
Back to examples

Related examples