This code snippet is currently functional, but it only retrieves the JSON response for the first set of parameters.
I am looking to make multiple calls to an external API with different parameters and then combine all the responses into one concatenated JSON response.
While I have two sets of parameters in this code, ideally I would like to have around 200. Any assistance on achieving this would be greatly appreciated.
const SerpApi = require('google-search-results-nodejs');
const search = new SerpApi.GoogleSearch("674d023b72e91fcdf3da14c730387dcbdb611f548e094bfeab2fff5bd86493fe");
const handlePictures = async (req, res) => {
const params1 = {
q: "kevin durant",
tbm: "isch",
};
const params2 = {
q: "lou williams",
tbm: "isch",
};
return new Promise((resolve, reject) => {
const callback1 = function(data) {
// console.log(data);
// res.send(data);
resolve(data);
};
// Show result as JSON
search.json(params1 , callback1);
// how do I get this to work too? ----> search.json(params2, callback1);
// res.end();
})
};
module.exports = {handlePictures};