Chrissy
Chrissy

Reputation: 11

How to make a simple API call with Spoonacular

I'm trying to render results on a webpage for a simple ingredient search with the Spoonacular API. I want to hard code the ingredients in the call, as seen in the URL below. I do have an API key and see the results when I put the below URL in the browser, but my script doesn't render it on my HTML page.

https://api.spoonacular.com/recipes/findByIngredients?ingredients=apples,+flour,+sugar&number=2

Here's what I've tried so far:

<p id="demo"></p>

<script>
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
  if (this.readyState == 4 && this.status == 200) {
    var myObj = JSON.parse(this.responseText);
    document.getElementById("demo").innerHTML = myObj.title;
  }
};
xmlhttp.open("GET", "https://api.spoonacular.com/recipes/findByIngredients?ingredients=bread,+flour,+sugar&number=2", true);
xmlhttp.send();
</script>

https://spoonacular.com/food-api/docs#Search-Recipes-by-Ingredients

Upvotes: 1

Views: 1018

Answers (0)

Related Questions