Kumar AU

Kumar AU

  • 1.4k
  • 309
  • 60.6k

How to make single API call with parallel logic

Aug 28 2023 2:40 AM

This is my code, here I need make "GetId" API call in parallel for better performance for my custom API, kindly let me know how do I make this. 

foreach(ResponseModel AccountSwap in invalidRecords) {
    this.ValidatePolicyExist(AccountSwap, bpValidPolicyDataTable);
}
private void ValidatePolicyExist(ResponseModel policyDetails, DataTable ValidDataTable) {
    if (this.IsPolicyExist(policyDetails.CorrectPolicyNumber)) {
        var row = ValidDataTable.NewRow();
        row["IncorrectReference"] = policyDetails.IncorrectNumber;
        row["CorrectReference"] = policyDetails.CorrectNumber;
        ValidDataTable.Rows.Add(row);
    }
}
private bool IsPolicyExist(string policyNumber) {
    var accountId = GetId(policyNumber).Result;
    // This API will return BIGINT number as a response if the records exist 
    return accountId != null;
}
public class ResponseModel {
    public string IncorrectNumber {
        get;
        set;
    }
    public string CorrectNumber {
        get;
        set;
    }
}

Here please let me know how I make the “GetId()” API call in parallel call, by doing this my API will be bit faster, kindly help me. I tried doing without parallel it takes 28 seconds for 100 records, but this is more time – we need to reduce to less than 10 second – kindly let me know


Answers (2)