Hi. Here is a simple example using promises.
'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 = [
'http://endpoint1.com',
'http://endpoint2.com',
'http://endpoint3.com'
];
// 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
});
On Tuesday, June 2, 2015 at 11:51:04 AM UTC-7, Tomas Garijo wrote:
>
> Hello.
> I need to call many servers with xml documents. Some servers can last more
> time to response and others less. After some time I have collect all
> responses and make a xml document. What mechanism I have to use to
> implement this?
>
> Regards.
>
>
>
>
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/aa797623-3f86-485d-b410-b347841e215c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.