Recipe - Food - Nutrition

FREEMIUM
Verified
Por David | Actualizada il y a 6 jours | Food
Popularidad

9.9 / 10

Latencia

1,904ms

Nivel de servicio

100%

Health Check

N/A

Volver a todas las conversaciones

Rapid API call in a 'fetch' request?

Rapid account: John Pett
JohnPett
il y a 5 ans

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

Únase a la conversación, añada un comentario a continuación:

Inicie sesió/Regístrese para publicar nuevos comentarios