'use strict';
// require the `request` module
var request = require('request');
// `gets` will hold an array of requests to send
var gets = [];
// here are the APIs you want to hit
var endpoints = [
];
// build up the `gets` array
endpoints.forEach(function (url) {
var req = new Promise(function (resolve, reject) {
// this is a simple GET with the `request` module
return request(url, function (err, res, body) {
// success: resolve the body content
if (!err && res.statusCode === 200) {
return resolve(body);
}
else {
// reject with a useful error
reject(YouErrorHere);
}
});
});
gets.push(req);
});
// send all requests and wait until they have all succeeded or one give an error
return Promise.all(gets)
.then(function (responseObjects) {
// do something with array of response objects
});