|
1 |
| -// const recipeUrl = "https://api.spoonacular.com/recipes/random?number=5&apiKey=fa31546b9db54de4ac0d528cc21fb947"; |
2 |
| -const fetch = require('node-fetch'); |
3 |
| -const apiKey = 'ac1e1c1767144e209bd7a0c6b23e1fbd' |
4 |
| -//'dfc52b1bc87a4054b99d6655d10c4206' |
5 |
| -//'c537cbd90c1149d38dc9a8b908755414' |
6 |
| -// 'f7a2ad99effc4441a00ad3cad3d7e8e6' |
7 |
| -// 'dfc52b1bc87a4054b99d6655d10c4206' |
8 |
| -//a565bdef05084ea48e7946a141f910c7 |
9 |
| -// 'ac1e1c1767144e209bd7a0c6b23e1fbd' |
10 |
| -//fa31546b9db54de4ac0d528cc21fb947 |
| 1 | +const fetch = require("node-fetch"); |
| 2 | +const apiKey = "a565bdef05084ea48e7946a141f910c7"; |
| 3 | +// f7a2ad99effc4441a00ad3cad3d7e8e6 |
| 4 | +// dfc52b1bc87a4054b99d6655d10c4206 |
| 5 | +// a565bdef05084ea48e7946a141f910c7 |
| 6 | +// fa31546b9db54de4ac0d528cc21fb947 |
| 7 | +// dfc52b1bc87a4054b99d6655d10c4206 |
| 8 | +// ac1e1c1767144e209bd7a0c6b23e1fbd |
| 9 | +// fa31546b9db54de4ac0d528cc21fb947 |
11 | 10 | // c537cbd90c1149d38dc9a8b908755414
|
12 |
| -//589362322c514340af0a24e58d162020 |
| 11 | +// 589362322c514340af0a24e58d162020 |
| 12 | + |
13 | 13 |
|
14 | 14 | const getRecipesApi = () => {
|
15 |
| - const recipeUrl = `https://api.spoonacular.com/recipes/random?number=5&apiKey=${apiKey}`; |
| 15 | + const recipeUrl = `https://api.spoonacular.com/recipes/random?number=10&tags=savoury&apiKey=${apiKey}`; |
16 | 16 | // console.log('(apiCall) getRecipesApi (fetch) runs and input = ', recipeUrl);
|
17 | 17 | return fetch(recipeUrl)
|
18 | 18 | .then(data => data.json())
|
19 | 19 | .then(data => {
|
20 | 20 | let fiveRecipe = {};
|
21 |
| - for (let i = 0; i < data.recipes.length; i++) { |
22 |
| - fiveRecipe[i] = {}; |
23 |
| - fiveRecipe[i].id = data.recipes[i].id; |
24 |
| - fiveRecipe[i].recipeName = data.recipes[i].title; |
25 |
| - fiveRecipe[i].cookingTime = data.recipes[i].cookingMinutes; |
26 |
| - fiveRecipe[i].healthScore = data.recipes[i].healthScore; |
27 |
| - fiveRecipe[i].imageUrl = data.recipes[i].image; |
| 21 | + if (data.status === 'failure') { |
| 22 | + fiveRecipe[0] = {}; |
| 23 | + fiveRecipe[0].recipeName = 'Our API has let us down, sorry'; |
| 24 | + } else { |
| 25 | + for (let i = 0; i < data.recipes.length; i++) { |
| 26 | + fiveRecipe[i] = {}; |
| 27 | + fiveRecipe[i].id = data.recipes[i].id; |
| 28 | + fiveRecipe[i].recipeName = data.recipes[i].title; |
| 29 | + fiveRecipe[i].cookingTime = data.recipes[i].cookingMinutes; |
| 30 | + fiveRecipe[i].healthScore = data.recipes[i].healthScore; |
| 31 | + fiveRecipe[i].imageUrl = data.recipes[i].image; |
| 32 | + } |
28 | 33 | }
|
29 | 34 | return fiveRecipe;
|
30 | 35 | })
|
|
0 commit comments