Recipe - Food - Nutrition

FREEMIUM
Verified
By David | Updated 23 days ago | Food
Popularity

9.9 / 10

Latency

1,410ms

Service Level

100%

Health Check

N/A

Back to All Discussions

Rapid API call in a 'fetch' request?

Rapid account: John Pett
JohnPett
5 years ago

Hello there!

I’ve only wanted to consume the API calls in React or a front-end framework, so don’t want to use the ‘unirest’ npm module. Is there a way to do it with a ‘fetch’ request? When I do it this way I get an empty object returned and no error:

const headers = new Headers({
“X-RapidAPI-Host”: “spoonacular-recipe-food-nutrition-v1.p.rapidapi.com”,
“X-RapidAPI-Key”: “MY_API_KEY”
})

const options = {
method: “GET”,
headers: headers
};

fetch(‘https://spoonacular-recipe-food-nutrition-v1.p.rapidapi.com/recipes/quickAnswer?q=Gluten+free+brownies’, options)
.then(function(response) {
return response.json();
})
.then(function(myJson) {
console.log(JSON.stringify(myJson));
})
.catch(function(error) {
console.log('There has been a problem with your fetch operation: ', error.message);
});

Join in the discussion - add comment below:

Login / Signup to post new comments