Lesson 40 of 55
javascriptWorking with APIs
20 mins
Course progress73%
What you'll learn
Keep these ideas in mind as you work through the lesson.
Lesson 40 of 55
javascript20 mins
Keep these ideas in mind as you work through the lesson.
Most modern services expose a JSON‑based HTTP API. The fetch library makes consuming these APIs effortless.
import fetch from 'node-fetch'; // for Node, or use the native fetch in browsers
const apiUrl = 'https://api.github.com/repos/javascript/cjavascript';
fetch(apiUrl)
.then(resp => resp.ok ? resp.json() : Promise.reject(resp.status))
.then(data => console.log('Stars:', data.stargazers_count))
.catch(err => console.error('Error:', err));
Authentication (API keys, OAuth) and pagination are common advanced topics you’ll encounter in real‑world integrations.