JavaScript 2025 · Promises and fetch

Fetch JSON

Request JSON and check for HTTP errors. fetch only rejects on network failures.

const res = await fetch("/api/users");
if (!res.ok) throw new Error(`HTTP ${res.status}`);
const users = await res.json();

Official JavaScript 2025 documentation

More promises and fetch commands

All promises and fetch commands · JavaScript 2025 cheatsheet

Was this page helpful?