NodeJS request multiple api endpoints
<p>Ok so I am trying to make two or more requests to API endpoints using the request module. I am rendering a HTML file and passing the returned JSON to a handlebars template using the below code:</p>

<pre><code>res.render('list.html', {
  title: 'List',
  data: returnedJSON
}
</code></pre>

<p>I can then iterate over this JSON within my handlebars template fairly easily.</p>

<p>The problem I have, is that I am now needing to use multiple data sources where a category list will be built from a categories JSON response and a Staff list from a staff JSON response. I would like a simple solution where I can do this, but expand it to use any number of data sources.</p>

<p>Below is a full code snippet of what I have with one data source:</p>

<pre><code>request({
    url: 'https://api.com/categories',
    headers: {
        'Bearer': 'sampleapitoken'
    }
}, function(error, response, body) {
    if(error || response.statusCode !== 200) {
        // handle error
    } else {
        var json = JSON.parse(body);
        res.render('list.html', {
            title: 'Listing',
            data: json
        });
    }
});
</code></pre>

<p>This works great for one endpoint, but as mentioned before I now need to use multiple requests and have multiple data sources for example:</p>

<pre><code>request({
    url: ['https://api.com/categories','https://api.com/staff'],
    headers: {
        'Bearer': 'sampleapitoken'
    }
}, function(error, response, body1, body2) {
    if(error || response.statusCode !== 200) {
        // handle error
    } else {
        var json1 = JSON.parse(body1);
        var json2 = JSON.parse(body2);
        res.render('list.html', {
            title: 'Listing',
            staff: json1,
            categories: json2
        });
    }
});
</code></pre>

<p>I appreciate the above doesn't work like that, but I hope this can help convey what I am trying to achieve.</p>

<p>Thanks in advance :)</p>