'What is the right way for multiple api call?
I'm doing a project that updates many patients' information with axios call. I parsed the patient's csv file to JSON format. And, call post api to update each patient's information like below.
/**
* this.csvJson.data : List of JSON format, each json contain one patient's information
*/
.
.
await this.csvJson.data.map(async (data)=>{
await axios.post(`api/MetaData/${this.projects.projectId}`,data)
.then(response=>{
//response handling
})
.catch(error=>{
//error handling
})
})
.
.
In this case, when the patient number is below 200, the uploading process is comparatively stable. But when patients number is over 20000, Browser has no response. I think calling multiple api for each patient cause browser crash.
What is the right way for handling multiple api call like this?
Solution 1:[1]
For multiple apiCall using Promise.all is often a better otpion, but i dont know if it can handle 20 000requests
const promises = csvJsonData.map((patientData) => {
return axios.post(`api/MetaData/${this.projects.projectId}`, data);
});
Promise.all(promises)
.then((response) => {
//response handling
})
.catch((error) => {
//error handling
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Johan Petrikovsky |
