Lesson 40 of 55 · javascript
Working with APIs
Duration: 20 mins
Working with APIs
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.