Best way to access API from React App?
<p>What's the best way for me to access an API using a React app? The API is currently developed in Golang using kami &amp; mgo for the POST/GET/DELETE requests. </p>

<p>I want to be able to make a GET request to the following URL: </p>

<p><a href="http://user:password@localhost:8000/api/v1/systems" rel="nofollow noreferrer">http://user:password@localhost:8000/api/v1/systems</a></p>

<p>on my React app and store the result in a state attribute:</p>

<pre><code>this.state = {
    data: //store the data here
}
</code></pre>

<p>I also want to load this data whenever the page is loaded so maybe I should use the componentDidMount() function to handle this?</p>

<p>I've never used API calls on React, so I was wondering if anyone here could tell me a good way to this?</p>

<p><strong>EDIT</strong></p>

<p>I'm using React 15.3.2.</p>

<p><strong>EDIT #2</strong></p>

<p>I've taken a look at <em>fetch</em> to handle the requests, but I'm still unsure how to use it in my situation. I've got the react app running on localhost:3000 and the api running on localhost:8000, /api/v1/systems will return a JSON with the following format:</p>

<pre><code>{ systems : [ //list of objects ] }
</code></pre>

<p>I've tried the following inside my componentDidMount():</p>

<pre><code>fetch(myRequest) 
  .then(result =&gt; {
    console.log(result);
    //this.setState({ data: result.json() });
    });
</code></pre>

<p>Not too sure what myRequest should be (been trying with a simple string of the URL: '<a href="http://localhost:8000/api/v1/systems" rel="nofollow noreferrer">http://localhost:8000/api/v1/systems</a>') and I'm also not sure if the ports where the apps are running could make a conflict or something. </p>