Hi, I want to work with the multiple API requests and insert data to DB in a single API request in .net core and I want that these multiple calls work parallelly so what is the best approach doing this so
Loading
Hi, I want to work with the multiple API requests and insert data to DB in a single API request in .net core and I want that these multiple calls work parallelly so what is the best approach doing this so
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mahesh ChandRank #1 · 393.3K reputationPosted Sep 1, 2021, 9:19 AM EDT
Priyanka K SRank #1,385 · 1.2K reputationPosted Sep 1, 2021, 1:49 PM EDT
Hi,
create async API and use await while calling other API's.
create a generic function to call all API's. You will get the c# code in PostMan you can use that.
then create a separate task for each api calls in Main Api:
var Task1 = await Task.Run(() => GenericMethod(parameters)); // API 1 url, its token and other parameters
var Task2 = await Task.Run(() => GenericMethod(parameters));// API 2 url, its token and other parameters
then call all API
Task.WaitAll(new [] {Task1, Task2});
Hope this helps.
Sachin SinghRank #66 · 26.2K reputationPosted Sep 1, 2021, 5:05 AM EDT
Abhishek ChadhaRank #402 · 6.2K reputationPosted Sep 1, 2021, 8:38 AM EDT
Abhishek ChadhaRank #402 · 6.2K reputationPosted Sep 1, 2021, 9:37 AM EDT
In the actual scenario there is no DB insertion, in my API call I need to call Another API's say 3-4, and then this 3-4 APIs response i need to send to azure blob storage.
so my concern is which is the better way to call these 4 APIs concurrently so that they process their work parallelly and there is no dependency on each other. I just want to save the processing time of my first API call