Level 3 · Programming Skills · Course 3.1 JavaScript Programming
Module 25: APIs and JSON
Goal: understand what an API is, read and write JSON, fetch data from real APIs, understand requests and responses, and handle keys, errors and limits safely. You'll build Project C, an API data viewer.
You'll need: your level-3 folder and Module 24.
Lessons
- 1What an API is15–25 minutes✓
- 2JSON15–25 minutes✓
- 3Fetching data15–25 minutes✓
- 4Requests and responses in detail15–25 minutes✓
- 5Keys, limits and safety15–25 minutes✓
🛠️Module practice: Project C, an API data viewer
Build viewer.js (in Node.js) or a page with viewer.html (in the browser) that:
- Takes a GitHub username (from the command line,
process.argv[2], or a form field). - Fetches the user and their public repositories (
/users/NAME/repos). - Shows name, number of repositories, and the five most recently updated repositories, sorted.
- Handles: a user that doesn't exist, no internet, and the rate limit (
403or429), each with a clear message. - Never uses
innerHTMLfor data from the API.
Commit.
✅Module check
Explain in a few sentences, in your own words:
What happens when your app gets data from an API, and what can go wrong?
Show a good answer
A good answer mentions: the app sends an HTTP request (method, address, headers, maybe a JSON body) to an
endpoint; the server replies with a status code and usually JSON, which is parsed. Things that go wrong: network
failure, 4xx errors (bad request, not found, not allowed, rate limited), 5xx server errors, unexpected data, and
CORS blocks in browsers. fetch doesn't fail on 4xx/5xx, so response.ok must be checked. API keys are secrets
kept on the server, never in frontend code or Git.
📝Module quiz
10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·
