vscode-restclient: response variable does not get resolved
-
VSCode Version: 1.22.1 Shell 1.7.12 Renderer 58.0.3029.110 Node 7.9.0 Architecture x64
-
OS Version: Windows 10 Home, Build Ver 1709
-
REST Client Version: 0.18.1
Steps to Reproduce:
###
# @name session_token
GET {{baseUrl}}/services/session/token HTTP/1.1
content-type: application/json
###
# @name login
POST {{baseUrl}}/api/user/login HTTP/1.1
content-type: application/json
X-CSRF-Token: {{login_token}}
test: {{session_token.response.body}}
{
"some" : "json"
}
Sending session_token returns body:
9m5UzOssDiuKpqlYb0HPIlPy7i7Q4ulBDCdeaaaaaaaaaa
Send request login actually sends (as caught by fiddler):
POST /api/user/login HTTP/1.1
content-type: application/json
X-CSRF-Token: 9m5UzOssDiuKpqlYb0HPIlPy7i7Q4ulBDCde34t80hc
test: {{session_token.response.body}}
User-Agent: vscode-restclient
host: some_host
accept-encoding: gzip, deflate
content-length: 76
Connection: keep-alive
I get a warning for a line “test: {{session_token.response.body}}”
"owner": "_generated_diagnostic_collection_name_#0",
"code": "undefined",
"severity": 4,
"message": "Body path should be provided right after \"body\"",
For now I have to copy the token manually to a variable but according to the docs I should be able to use like test: {{session_token.response.body}} unfortunetly session_token.response.body does not gets resolved
In this case, what seems to be expected is that the whole body is saved in variable
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 19 (9 by maintainers)
Commits related to this issue
- Allow to fetch whole document for xml response #188 — committed to Huachao/vscode-restclient by Huachao 6 years ago
- Support fetch the whole response/request body regardless of the content-type #188 — committed to Huachao/vscode-restclient by Huachao 6 years ago
@abenedykt got, as you said previously, I should implement a selector to fetch the whole response body, instead of extracting specific attribute of
json
andxml
responses.@xywwf personally I think we only need to update the JSON MIME type validation logic and make your response pass the check
@xywwf since the
Content-Type
of response is notapplication/json
, I will consider if I can improve this, thanks for mentioning this@sanpee @abenedykt @lldata @mladengit I have adopted @sanpee’s suggestion, and use the syntax
{{request_variable_name.response|request.body.*}}
to retrieve the whole response body regardless of the content-type.I just started to use this extension in complement with Postman. Very useful extension.
Instead of
{{session_token.response.body.$}}
, can{{session_token.response.body.*}}
be used to get all the body content regardless Content-Type. I think that only need a minor change in requestVariableCacheValueProcessor.ts.@abenedykt under the premise that content type of response body should be
json
orxml
, we could successfully extract the body value. And if your response body actually matches the case, you should provide theJSONPath
orXPath
to extract the expected part as described in warning message. In your case, if your response body is only filled with9m5UzOssDiuKpqlYb0HPIlPy7i7Q4ulBDCdeaaaaaaaaaa
, it should work like{{session_token.response.body.$}}