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

Support resolving arrays in query string and body

Open eamodio opened this issue 6 years ago • 8 comments

  • VSCode Version: 1.23
  • OS Version: Windows 10
  • REST Client Version: 0.18.2

I would really like the ability to use a jsonpath query that resolves to an array in both the query string and request body.

Here is an example:

# @name data
POST http://httpbin.org/post
Content-Type: application/json

{
    "teams": [
        {
            "id": "1",
            "name": "Team 1"
        },
        {
            "id": "2",
            "name": "Team 2"
        },
        {
            "id": "3",
            "name": "Team 3"
        }
    ]
}

###

# Resolves to http://httpbin.org/get?ids=1
# Want it to resolve to http://httpbin.org/get?ids=1,2,3 

GET http://httpbin.org/get?ids={{data.response.body.$.json.teams[*].id}}
Content-Type: application/json

###

# Resolves to { "ids": "1" }
# Want it to resolve to { "ids": [1,2,3] }

POST http://httpbin.org/post
Content-Type: application/json

{
    "ids": "{{data.response.body.$.json.teams[*].id}}"
}

Awesome extension BTW!

eamodio avatar Apr 23 '18 02:04 eamodio

@eamodio nice suggestion, interesting idea.

Huachao avatar Apr 23 '18 03:04 Huachao

Thanks -- fyi, it seems somewhat like a bug right now that a jsonpath query like {{data.response.body.$.json.teams[*].id}} is currently equivalent to {{data.response.body.$.json.teams[0].id}}

eamodio avatar Apr 23 '18 03:04 eamodio

@eamodio actually it's by design https://github.com/Huachao/vscode-restclient/blob/52c99ab27da93ee03d6262d20016cd7611565cd5/src/requestVariableCacheValueProcessor.ts#L85-L86

Huachao avatar Apr 23 '18 05:04 Huachao

is there any plan to support this feature?

niusounds avatar Jul 09 '20 04:07 niusounds

@niusounds I am still planing this since I met a problem. What's the string representation(serialization) of the array result, simply JSON stringify the array or something else?

Huachao avatar Jul 09 '20 04:07 Huachao

@Huachao, I do have the same need. I was taking a look on this link and I do believe that a JSON stringify with the correct replacer, would do the job for most cases. Please, take a look and see what do you think about it.

Cheers

rodrigoestevao avatar Aug 27 '20 12:08 rodrigoestevao

I would love to have this as well 👍

fskroes avatar Sep 26 '20 11:09 fskroes

This would be an awesome addition please merge #853

gertjvr-jb avatar Jul 11 '22 03:07 gertjvr-jb