Created
November 17, 2017 10:47
-
-
Save cookie-ag/ebea6717ce92df88061b0b96bef7c63e to your computer and use it in GitHub Desktop.
Multiple Requests (Promisified)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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