I am new to both promises and having trouble understanding what I need to do to code the following logic:
I am developing a Web service in Node.js and Express to fetch song data from a wiki and return an object, which a client application will consume. The wiki's API does not let me write a batch query; I have to get each page individually. So I will have to get the list of songs, then perform a call for each song.
I currently intend to use the Q middleware for Node.js as my promises library, though I am open to suggestions on a more appropriate middleware for this task.
Here is my pseudocode:
app.get('/songs/:criteria', function(request,response) {
downloadSongList()
.then(foreach(song) downloadSongData)
.then(assembleReturnValue)
.then(response.json(returnValue));
});
What will the actual code look like?