vscode-restclient
vscode-restclient copied to clipboard
Support resolving arrays in query string and body
- 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 nice suggestion, interesting idea.
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 actually it's by design https://github.com/Huachao/vscode-restclient/blob/52c99ab27da93ee03d6262d20016cd7611565cd5/src/requestVariableCacheValueProcessor.ts#L85-L86
is there any plan to support this feature?
@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, 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
I would love to have this as well 👍
This would be an awesome addition please merge #853