Chapter practice task
Task: Add a live data section and a saved preference to your site
- Fetch a list of items from a public JSON API.
- Show a loading message, then the results as cards.
- Show a friendly message if the request fails.
- Rewrite the code with async/await and try/catch.
- Save one preference (like a selected filter) in localStorage and restore it on reload.
By the end of this chapter
- You can request JSON data with fetch and display it on the page
- You can write asynchronous code with async/await and handle errors
- You can store and read data in localStorage
Quick answers for this chapter
What’s an API?
A URL that returns data (usually JSON) instead of a web page, so your code can use it.
Do I need a server for this?
Not for reading public APIs. Your code runs in the browser and requests the data directly.
Is localStorage a database?
No. It’s small, per-browser storage for settings and drafts, not for important or shared data.