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
- POST JSON
- Time out a request
- Handle errors in async code
- Run promises in parallel
- Wait for all promises, whatever happens
- Pause for a while
All promises and fetch commands · JavaScript 2025 cheatsheet