Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to call HttpClientRequest in batch mode

Avatar

Avatar
Validate 1
Level 1
JamesAlio
Level 1

Likes

0 likes

Total Posts

11 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile

Avatar
Validate 1
Level 1
JamesAlio
Level 1

Likes

0 likes

Total Posts

11 posts

Correct Reply

0 solutions
Top badges earned
Validate 1
View profile
JamesAlio
Level 1

19-01-2021

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.

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Establish
MVP
wodnicki
MVP

Likes

960 likes

Total Posts

1,090 posts

Correct Reply

509 solutions
Top badges earned
Establish
Affirm 500
Contributor
Shape 1
Give Back 100
View profile

Avatar
Establish
MVP
wodnicki
MVP

Likes

960 likes

Total Posts

1,090 posts

Correct Reply

509 solutions
Top badges earned
Establish
Affirm 500
Contributor
Shape 1
Give Back 100
View profile
wodnicki
MVP

20-01-2021

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

Answers (0)