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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Priyanka K SPosted Sep 1, 2021, 5:49 PM
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.
Abhishek ChadhaPosted Sep 1, 2021, 1:37 PM
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
Mahesh ChandPosted Sep 1, 2021, 1:19 PM
Abhishek ChadhaPosted Sep 1, 2021, 12:38 PM
Sachin SinghPosted Sep 1, 2021, 9:05 AM