Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

Correlating request and response for REST service invocations

I am invoking a rest services in a loop that iterates over an array of request elements. The response is mapped to a JS in Appery. I need to be able to track in the JS which request generated a particular response. The service response parameters themselves don't have information for me to identify the request.

How can I solve this issue?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Correlating request and response for REST service invocations

Hi Cody,

It's hard to say as it's up to your app logic.
You can use localStorage to map Service response and then call its value as request parameter http://docs.appery.io/documentation/r...

Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

Correlating request and response for REST service invocations

Sure, I am enumerating the scenario at hand with my app logic:

for (var i=0; it support for it?

Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

Correlating request and response for REST service invocations

Sure, I am enumerating the scenario at hand with my app logic:

for (var i equals 0; i less than input_elements_array.length; increment i) {
service.execute( data: input_elements_array);
}

Since the invocation is asynchronous and all the invocations above can go in parallel, its hard to map to Local Storage elements as you suggest.

Will appreciate your feedback in helping me resolve this need. Is there a way for instance to artificially return an identifying parameter in the response, even if the REST server doesn't support for it?

Alena Prykhodko
Posts: 0
Joined: Tue Apr 09, 2013 7:36 am

Correlating request and response for REST service invocations

Cody,

Use this code:
pre
var RunService(data){
var inputElement = data.inputElement;
var index = data.index;

Code: Select all

 var onSuccess = function(){ 
     //Here is "inputElement" and "index" variables are avaliable for use. 
     //Place code to handle response here. 
 }; 

 service.execute({data: inputElement, success: onSuccess}); 

};

for(var i == 0; i < input_elements_array&#46;length; i++)
RunService({index: i, inputElement: input_elements_array});

/pre

As Success event handler overrided, your javascript handler in events tab would not run for this datasource. You should implement all response logic here.

Cody Blue
Posts: 0
Joined: Sun Aug 25, 2013 2:11 am

Correlating request and response for REST service invocations

Thank you! One minor fix for someone who might be reading and would want to benefit from it, the following modification to the above suggestion worked for me:

function RunService(data)

Thanks again.

Return to “Issues”