Recipe - Food - Nutrition

FREEMIUM
Verified
Par David | Mise à jour 6 дней назад | Food
Popularité

9.9 / 10

Latence

1,904ms

Niveau de service

100%

Health Check

N/A

Retour à toutes les discussions

Rapid API call in a 'fetch' request?

Rapid account: John Pett
JohnPett
5 лет назад

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);
});

Participez à la discussion - ajoutez un commentaire ci-dessous:

Connectez-vous / Inscrivez-vous pour publier de nouveaux commentaires