var request = require('request');
request('http://www.test.com/api1', function (error, response, body) {
if (!error && response.statusCode == 200) {
request('http://www.test.com/api1', function (error, response, body) {
if (!error && response.statusCode == 200) {
request('http://www.test.com/api1', function (error, response, body) {
if (!error && response.statusCode == 200) {
}
})
}
})
}
})
Depending on which version of node you are using, promises should be native...
https:
https:
var request = require('request');
getRequest('http://www.test.com/api1').then(function (body1) {
return getRequest('http://www.test.com/api2');
}).then(function (body2) {
return getRequest('http://www.test.com/api3');
}).then(function (body3) {
});
function getRequest(url) {
return new Promise(function (success, failure) {
request(url, function (error, response, body) {
if (!error && response.statusCode == 200) {
success(body);
} else {
failure(error);
}
});
});
}