Loop through an api get request with variable URL

前端 未结 2 590
没有蜡笔的小新
没有蜡笔的小新 2020-11-30 15:45

I am trying to call CompaniesHouse API and fetch companies registered between November and February. The approach I took is to pick a starting index(a company registered in

2条回答
  •  鱼传尺愫
    2020-11-30 16:46

    var needle = require("needle");
    var startIdx = 11059000;
    var stopIdx  = 11211109;
    const promises = [];
    for(idx = startIdx; idx < stopIdx; idx++)
    {
        promises.push(
            needle('get', "https://api.companieshouse.gov.uk/company/"+idx, { 
                username: key,password:"" 
            })
        )
    }
    
    Promise.all(promises).then(results => {console.log(results);}).catch(err => console.log(err));
    

    A simple Promise.all implementation can help.

提交回复
热议问题