Expand my Community achievements bar.

Adobe Campaign User Groups are live now. Join our Adobe Campaign User Groups and connect with your local leaders!
SOLVED

How to call HttpClientRequest in batch mode

Avatar

Level 2

Hello, I'm working on a workflow where I have to call an external API using HttpClientRequest and all work fine.
The API that I call uses pagination so I have to call the API to get results for each page. I have 10 pages so I have to make 10 calls. I'm wondering if there is a way to make only one call to get the result instead of 10 calls.

this is my current code : 

 

var requestUrl = "https://www.muapiurl.com?";

// 10 calls
for (var i = 1; i <= 10; i++) {

var requestParam = "page="+i;
var url = requestUrl+requestParam;

var request = new HttpClientRequest(url);

var bufferEm = new MemoryBuffer();
request.header["Content-Type"] = "application/json; charset=utf-8";


request.method = "GET";

request.execute();

var dataResponse = request.response;

var data = JSON.parse(dataResponse.body);

for each(var obj in data) {
//.........
}
}

 

Regards.

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi,

 

You can use keep-alive to reduce overhead, assuming server supports it:

Otherwise asynchronous mode can make the requests in parallel.

In the pasted code the MemoryBuffer is unneeded, and error handling should be added.

 

Thanks,

-Jon

View solution in original post

1 Reply

Avatar

Correct answer by
Community Advisor

Hi,

 

You can use keep-alive to reduce overhead, assuming server supports it:

Otherwise asynchronous mode can make the requests in parallel.

In the pasted code the MemoryBuffer is unneeded, and error handling should be added.

 

Thanks,

-Jon