Explanation
APIs let your frontend fetch and send data using REST or similar HTTP interfaces.
Code example
typescripttype Roadmap = {
id: string;
title: string;
difficulty: "BEGINNER" | "INTERMEDIATE" | "ADVANCED";
};
export async function getRoadmaps(): Promise<Roadmap[]> {
const response = await fetch("/api/roadmaps");
if (!response.ok) {
throw new Error("Failed to load roadmaps");
}
return response.json();
}Exercise
Fetch a public API, show loading/error/success states, and render the results in a list.
