Send Multiple Http Request Via Parse.cloud.httpreq
I'm trying to send multiple HTTP Requests via Parse.Cloud.httpRequest but I get {'code':141,'message':'Error: Can't call success/error multiple times I need to do all requests a
Solution 1:
The trick is to collect promises to complete the http requests, then set the response "when" the promises are complete.
Parse.Cloud.define('http', function(request, response) {
var promises = [];
for (var i = 0; i < request.params['params'].length; i++) {
var object = request.params['params'][i];
promises.push(makeRequestWithObject(object));
}
Parse.Promise.when(promises).then(function() {
// results are passed to this function as var args
response.success(arguments);
}, function(error) {
response.error(error);
});
});
// return a promise to complete an http request with object
function makeRequestWithObject(object) {
var url = 'http://185.xxxxxxx'+ object +'&languagePath=en';
return Parse.Cloud.httpRequest({ url:url });
}
Post a Comment for "Send Multiple Http Request Via Parse.cloud.httpreq"