title: How can I use unirest API calls in React?
body: <p>I'm working with <code>unirest</code> API calls and React for the first time and I'm having trouble implementing a <code>unirest</code> call. While it works in a simple Node.js program, if I try to plug the code below into a React.js file and work with it, I'm unable to get any results for some reason, as I just get an undefined object back.</p>
  
  <p><a href="https://i.stack.imgur.com/X2ho4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/X2ho4.png" alt="console description"></a></p>
  
  <pre><code>var unirest = require('unirest');
  unirest.get(--insert url here--)
  .header("X-Mashape-Key", --insert key here--)
  .header("X-Mashape-Host", "spoonacular-recipe-food-nutrition- 
  v1.p.mashape.com")
  .end(function (result) {
    console.log(result.status, result.headers, result.body);
  });
  </code></pre>
  
  <p>However, when I plug this into a barebones Node.js file, I get an object back with the values I want. I've been struggling with this for days -- does anyone have any idea what I'm doing wrong?</p>
  
  <p>EDIT: Here is how I tried to implement this in React:</p>
  
  <pre><code>import React from 'react';
  import './App.css';
  var unirest = require('unirest');
  
  class Kitchen extends React.Component {
    callApi() {
      unirest.get(--insert api url--)
      .header("X-Mashape-Key", --insert api key--)
      .header("X-Mashape-Host", "spoonacular-recipe-food-nutrition- 
      v1.p.mashape.com")
      .end(function (result) {
        console.log(result.status, result.headers, result.body);
    });  
  
    render() {
      return(
        &lt;div className="ingredient-info"&gt;
          {this.callApi()}
        &lt;/div&gt;
      )
    }
  </code></pre>
  
  <p>EDIT 2: Here is what the expected Object body looks like:</p>
  
  <pre><code>[ { id: 556470,
      title: 'Apple fritters',
      image: 'https://spoonacular.com/recipeImages/556470-312x231.jpg',
      imageType: 'jpg',
      usedIngredientCount: 3,
      missedIngredientCount: 0,
      likes: 243 },
    { id: 73474,
      title: 'Apple Turnovers',
      image: 'https://spoonacular.com/recipeImages/73474-312x231.jpg',
      imageType: 'jpg',
      usedIngredientCount: 3,
      missedIngredientCount: 0,
      likes: 48 },
    { id: 47950,
      title: 'Cinnamon Apple Crisp',
      image: 'https://spoonacular.com/recipeImages/47950-312x231.jpg',
      imageType: 'jpg',
      usedIngredientCount: 3,
      missedIngredientCount: 0,
      likes: 35 } ]
  </code></pre>