JavaScriptJavaScript · Lesson 14

Fetch & APIs

Calling HTTP APIs and rendering JSON.

Video tutorialTrack course · freeCodeCamp
Speed
Next lesson
Watch 00:00 · 1 checkpoints Watch on YouTube More on this topic
Transcript & captions
4/4
jsjs
const res = await fetch('https://api.example.com/users');
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();
Try it yourself

fetch only rejects on network errors — a 404 or 500 still resolves, so always check res.ok.

Knowledge check

0/1 answered

Does fetch throw on a 500 response?