Skip to content

Instantly share code, notes, and snippets.

@cookie-ag
Created November 17, 2017 10:47
Show Gist options
  • Save cookie-ag/ebea6717ce92df88061b0b96bef7c63e to your computer and use it in GitHub Desktop.
Save cookie-ag/ebea6717ce92df88061b0b96bef7c63e to your computer and use it in GitHub Desktop.
Multiple Requests (Promisified)
var __request = require('./logic.js').__request;
var urls = ["http://www.example.com/firts", "http://www.example.com/second", "http://www.example.com/third"];
__request(urls, 'GET', false);
'use strict';
var request = require('request');
var rp = require('request-promise');
var __request = function(urls, HTTP_method, gzip_Boolean) {
var results = {};
var t = urls.length;
var c = 0;
while (t--) {
rp({
method: HTTP_method,
uri: urls[t],
gzip: gzip_Boolean
}).then(function(body){
results[t] = {
err: false,
data: response
};
console.log(results);
}).catch(function(error){
results[t] = {
err: {
status: true,
name: error.name,
message: error.message
}
};
console.log(results);
});
}
return results;
};
exports.__request = __request;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment