The CreatorCon Call for Content is officially open! Get started here.

Requesting Help : How to trigger two Async REST API call's go out concurrently

Supriya25
Tera Guru

Hi Team,

 

we have two REST API call's via MID-servers based on user inputs
if user gives his inputs any one of REST API call will trigger, if users doesn't give his input then two REST API call's will trigger.

Current SETUP : here system running API calls  sequentially 
example :

Field name : Requesting User input  
var gr1="";var gr2=""; var r ="".....etc;
if(Requesting User input  =="")
{
 gr1 = true;
 gr2 = true;
}
if(gr1)
{
r= new sn_ws.RESTMessageV2(........);
..
..
response=r.executeAsync();  // it is Asysnc Method
responseBoby = response.getBody();
httpstatus = response.getStatusCode(); // it is Sysnc Method
if(httpstatus==200){
some code will execute
}

if(gr2)
{
r= new sn_ws.RESTMessageV2(........);
..
..
response=r.executeAsync();  // it is Asysnc Method
responseBoby = response.getBody();
httpstatus = response.getStatusCode(); // it is Sysnc Method
if(httpstatus==200){
some code will execute
}

here at First -loop if(gr1) getStatusCode() making system to wait for httpcode this is Sync behavior and once code received, it's executes respective balance code and going to next loop if(gr2). until system get the HTTP code from first-loop system not jumping to next loop if(gr2). its wasting of huge time/ latency issues coming .

 

So How to over come this situation , how can we make system to do process the second loop also 


how to change API call's will go out  concurrently , Please share you inputs .


5 REPLIES 5

Hi Supriya,

Yes, this approach will allow you to call both the REST APIs with minimum time difference because we are calling first and executing the conditions next. 

Please test and let me know if it works for you.

 

If my answer has helped with your question, please mark my answer as accepted solution and give a thumbs up.

 

Best regards,

Tharun Kumar