Stage 6 · Lesson 4 of 8
Calling a public API with fetch
Current versions of Node.js have built in, the same API as in the browser. const res = await fetch(url) sends a . Like other , it resolves (finishes) as soon as a response arrives, even for a 404 or 500 error. fetch only rejects on network failures, so check res.ok or res.status before calling await res.json().
401 means a bad key and 429 means too many requests. Build with URLSearchParams rather than gluing strings together. Pass signal: AbortSignal.timeout(10000) so a slow server cannot hang your program.
Read the documentation for , and cache responses while developing. Wrap the call in one function that returns plain data or throws a clear error.
A question to check yourself, an AI practice session and 3 cheat sheet entries come when you add the roadmap to your account. Add it
Resources for this stage
Start with· follow one of these
- GitHub repoFreeProject Based Learning
Community maintained · Beginner
Follow one guided build in your language, then build your own without a guide
- BookFreeEloquent JavaScript
Marijn Haverbeke · Intermediate
Free: the project chapters (a robot, a programming language, a pixel editor) show real structure
Keep handy
Also worth your time
How to present each project: the problem, stack, challenges and results
- Build Your Own XGo deeper
When you want a harder build: a shell, a key-value store or a tiny Git, from scratch