Tutorial
How to Build a Meal Planner with Recipe API
A meal planner is mostly a data problem: you need consistent recipes, reliable macros, and a way to fill gaps when nothing in the catalog fits. This guide walks through building one end to end with Recipe API — discovery, macro filtering, assembling a week, and personalizing with generation. Every endpoint here is real, and you can run the curl examples as soon as you have a key.
1. Get a free API key
Start on the free tier — no card required. Create a key at recipe-api.com/signup, then send it on every request in the X-API-Key header. If you just want to see the shape of a response before signing up, the public /api/v1/dinner endpoint returns a sample recipe with no authentication.
curl "https://recipe-api.com/api/v1/dinner"
2. Build discovery from the taxonomy
Before you filter recipes, load the controlled vocabularies that power your planner's UI. Recipe API exposes three taxonomy endpoints — categories, cuisines, and dietary flags — so you can render real filter chips instead of hard-coding strings. Fetch them once at build time or cache them; they change rarely.
curl "https://recipe-api.com/api/v1/categories" -H "X-API-Key: rapi_your_key" curl "https://recipe-api.com/api/v1/cuisines" -H "X-API-Key: rapi_your_key" curl "https://recipe-api.com/api/v1/dietary-flags" -H "X-API-Key: rapi_your_key"
The values you get back — category names like Dinner, cuisines like Italian, and flags like Vegetarian or Gluten-Free — map directly to the query parameters on the recipe search endpoint. That consistency is the point: one schema means the same vocabulary flows from your filter UI straight into the API call.
3. Filter recipes by macros
The core of a planner is matching recipes to a target. The GET /api/v1/recipes endpoint accepts category, cuisine, dietary, max_calories, min_protein, ingredients, plus page and per_page. To find high-protein, calorie-capped dinners for a cut, combine them in one request.
curl "https://recipe-api.com/api/v1/recipes?category=Dinner&max_calories=600&min_protein=30&dietary=Gluten-Free&per_page=20&page=1" \ -H "X-API-Key: rapi_your_key"
Because every recipe carries the same 32 USDA-tracked nutrients per serving, the calorie and protein numbers you filter on are the same numbers you display and sum later — no normalization step. Use page and per_page to build a candidate pool of, say, 60-80 recipes per slot so your plan generator has room to balance variety.
4. Assemble a day and a week
With candidate pools per meal slot, planning becomes selection. A simple, reliable approach: set a daily calorie budget, split it across breakfast, lunch, and dinner, then pick one recipe per slot whose per-serving calories fit the remaining budget. Track running totals as you go so the day lands near target.
- Query a pool per slot using
categoryandmax_caloriessized to that slot's share of the budget. - Sum the per-serving calories and protein as you add recipes; reject picks that would overshoot the daily cap.
- Repeat for seven days, de-duplicating recipe slugs so the week stays varied.
- Render the structured instructions and grouped ingredients directly — they are machine-readable, so a shopping list is just a roll-up of ingredient IDs across the week.
Filter by pantry constraints with the ingredients parameter when a user wants to cook from what they have. Because ingredients are linked by ID, the same identifiers you pass as a filter are the ones you aggregate into a consolidated grocery list.
5. Personalize with generation
No catalog covers every household. When a user's combination of restrictions, goals, and tastes leaves a slot empty, fall back to POST /api/v1/generate to produce a fresh recipe that fits — returned in the exact same schema as cataloged recipes, including the full nutrition block. That means your rendering and macro-summing code paths stay identical whether a recipe came from the catalog or from generation.
curl -X POST "https://recipe-api.com/api/v1/generate" \
-H "X-API-Key: rapi_your_key" \
-H "Content-Type: application/json" \
-d '{
"category": "Dinner",
"dietary": ["Vegetarian", "Gluten-Free"],
"max_calories": 550,
"min_protein": 25
}'With discovery, macro filtering, weekly assembly, and generation in place, you have a complete planner: catalog recipes for breadth, and generation for the long tail of personal constraints — all sharing one schema, one nutrition model, and one set of dietary flags.
Build your planner today
Grab a free key and start hitting the same endpoints used in this guide.