What is an API?
An API (Application Programming Interface) is a server endpoint that returns data (usually JSON) when your browser sends an HTTP request to it. Weather apps, maps, social media feeds — all built on APIs.
JSON (JavaScript Object Notation) is the data format: key-value pairs that look exactly like JavaScript objects: {"name":"Alex","score":92}.
fetch() and async/await
async function loadUsers() {
try {
const response = await fetch("https://api.example.com/users");
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json(); // parse JSON
renderCards(data);
} catch (err) {
console.error("Fetch failed:", err);
}
}
async marks a function as asynchronous. await pauses execution until the Promise resolves. Always wrap in try/catch to handle network errors gracefully.