vscode-restclient icon indicating copy to clipboard operation
vscode-restclient copied to clipboard

How to run several requests in a kind of loop statement

Open anfisc opened this issue 3 years ago • 6 comments

I have the requirement to send nearly the same POST request to a backend system several times. The only difference is a varialble that I have set. @group_number = 0051 Within the payload of my request I would have something like "group_number" : "{{group_number}}" Currently I am editing the value and send the request manually. Is there a way to do this in a programmatic way? Sending N http requests thereby changing a variable so that the payload changes? Kind regards, Andre

anfisc avatar Sep 29 '21 17:09 anfisc

It would be nice if the API looks like this to keep my tool compatible with rest-client

for ... of ...

Variable $index and Variable Name is injected in Variables for every iteration

{{
  exports.data = [1, 2, 3];
}}
###
# @loop for item of data
GET https://httpbin.org/anything?item={{item}} HTTP/1.1

for ...

Variable $index is injected in Variables for every iteration

# @loop for 4
GET https://httpbin.org/anything?item={{$index}} HTTP/1.1

while ...

Variable $index is injected in Variables for every iteration

{{
  exports.expression = {
    index: 0,
  };
}}
###
# @loop while expression.index < 3
GET /anything?item={{expression.index++}} HTTP/1.1

AnWeber avatar Nov 02 '21 07:11 AnWeber

how can it use in POST body ??

yeahe83 avatar Feb 18 '22 11:02 yeahe83

Can this be configured to make the requests asynchronously so that httpyac doesn't wait for the responses?

joerg-walter-de avatar Dec 08 '22 14:12 joerg-walter-de

Any updates on this?

maracko avatar Sep 29 '23 13:09 maracko