I'm chaining Q promises:
Q(initialCall).then(someOtherCallThatUsesResultsFromPreviousResults)
A call usually means a promisified node.js http.get call to an external REST api. The path is constructed using information from previous call. At the same time I want to pipe the information from previous call as well. The final result from the chain should be data from both calls merged into one object. Right now the passing of the information is done explicitly via an additional parameter - object. Any way that would not require explicitly passing the extra parameter?
function jsonRequest(pathThatIsContructedBasedOnPreviousResults, object:any) {
var deferer = Q.defer();
var options = capsuleOptions;
options.path = path;
https.get(options, function (response) {
response.on('data', function (d) {
var parsedJson = JSON.parse(d);
deferer.resolve({data: parsedJson, object: object});
})}).on('error', function(e) {deferer.reject(e);});
return deferer.promise;
}
Example:
function getUserDetailsByEmail(email) {
var userByEmailRequestPath = '/api/party?email=' + email;
return jsonRequest(userByEmailRequestPath, email);
}
UserByEmail endpoint doesn't return email as part of response JSON and I still want to include email in the return value.