A recipe finder is a great JavaScript project because the data is fun and the API is free. TheMealDB is a free API that needs no API key at all — you can search thousands of recipes by name, ingredient, or category, and every recipe comes with a photo, instructions, and a video link.
The search is one fetch call:
async function searchRecipes(query) {
const res = await fetch(
`https://www.themealdb.com/api/json/v1/1/search.php?s=${encodeURIComponent(query)}`
);
const data = await res.json();
return data.meals || []; // null when nothing matches
}
Render the results as cards with the meal thumbnail, name, category, and area (cuisine). Clicking a card opens a detail view: fetch the full recipe with lookup.php?i=${id}, then list the ingredients. TheMealDB returns ingredients as strIngredient1 through strIngredient20 with matching measures, so loop through them and skip the empty ones:
function getIngredients(meal) {
const list = [];
for (let i = 1; i <= 20; i++) {
const item = meal[`strIngredient${i}`];
const measure = meal[`strMeasure${i}`];
if (item && item.trim()) list.push(`${measure} ${item}`);
}
return list;
}
Three features make it feel like a real app:
-
Filter by category and area. TheMealDB has endpoints for listing categories (
list.php?c=list) and areas — render them as dropdowns. -
Surprise me button. The
random.phpendpoint returns one random recipe — a one-line feature users love. -
Saved recipes. A heart button on each recipe stores its ID in
localStorage, and a "Saved" tab shows the collection.
This project teaches API integration, dynamic rendering, and localStorage in a single evening. As a stretch goal, add a "cook mode" view that shows one instruction step at a time with a checkbox for each step.
Top comments (0)