JavaScript Simplified · One concept, one day, one project · Day 29 of 32
Working With API Data
Taking a whole list of data from an API and drawing it on the page. Everything from the course meets here. You build a mini news app.
By the end of today you can
- Fetch a list of items from an API
- Loop over the data and build an element for each
- Read each object’s fields into a card
- Build a mini news app
Yesterday you fetched one country. Real apps fetch lists: many articles, many products, many messages, and draw a card for each. Today every layer of the course works together: fetch, async/await, JSON, arrays, objects and the DOM. This is what building a real feature feels like.
1. The Shape of the Job
A list-from-an-API feature is always the same four steps:
- Fetch the URL and await the response.
- Await response.json() to get an array of objects.
- Loop over the array (with forEach or map).
- For each object, build an element from its fields and add it to the page.
You have done every one of these separately. Today you join them.
2. Building a Card From Each Item
One fetch, one forEach, a card built from each article’s fields. This is a real feature: the exact pattern behind a news feed, a product grid, or a list of search results.
Today’s Mini Project
📰 Mini News App
The page above is your project: fetch a list of articles and show each as a card with a title, an image, a summary and a link. Point it at a real news API and it works the same way.
Before the loop, show how many articles were loaded, like "2 stories", by reading articles.length. Expected: a count above the cards.
Change forEach to build the cards with map and join("") into one innerHTML instead. Both work; see which you find clearer.
Expected: the same feed, built a different way.
A pile of JSON from a server became a tidy list of cards on your page. That transformation, data in, interface out, is most of what front-end developers do all day. You can now do it.
Checkpoint
What are the four steps of showing a list from an API?
Fetch the URL and await the response, await response.json() for an array, loop over the array, and build an element from each object to add to the page.
Why loop over the data?
Because the API returns many items. You build one card per item, which is how feeds, grids and search results are drawn.
Which earlier skills come together here?
fetch and async/await (Week 7), arrays and objects (Week 3), and the DOM (Week 4). A real feature uses the whole course at once.
Tick Before You Move On
- ☐ I can fetch a list from an API
- ☐ I can loop over the data
- ☐ I can build a card from each object
- ☐ I built the Mini News App
Quick Recap
Real apps fetch lists and draw one element per item. The steps: fetch, await json, loop, build and append. Each card is built from one object’s fields. This joins fetch, async, arrays, objects and the DOM into one feature.
Next: Day 30. Your news app forgets everything on refresh. Tomorrow you learn local storage, so your app can remember things in the browser.