The new feature where you can use information from the response in the following request is very nice. But it could be improved. This is the current version:
# @name createComment
POST {{baseUrl}}/comments HTTP/1.1
Authorization: {{login.response.headers.X-AuthToken}}
Content-Type: application/json
{
"content": "fake content"
}
###
# @name getCreatedComment
GET {{baseUrl}}/comments/{{createComment.response.body.$.id}} HTTP/1.1
Authorization: {{login.response.headers.X-AuthToken}}
I'd like if you could define a variable, with data captured from the response.
Like this:
# @name createComment
POST {{baseUrl}}/comments HTTP/1.1
Authorization: {{login.response.headers.X-AuthToken}}
Content-Type: application/json
{
"content": "fake content"
}
###
@commentId={{createComment.response.body.$.id}}
# @name getCreatedComment
GET {{baseUrl}}/comments/{{commentId}} HTTP/1.1
Authorization: {{login.response.headers.X-AuthToken}}
Currently @commentId will have the value "{{createComment.response.body.$.id}}"
I'd expect the second example to do the same as the first.
Just realized that my request looks a bit like #179
The difference is in the syntax on how you override a variable.
I'd say that the least surprising syntax is with the @ prefix ...
@lldata nice suggestion, it's different from that.
You could avoid holding all responses in memory, if you allowed a section below the request, that could post process the response. Like this:
# @name postjson
POST http://httpbin.org/post
{
"key1" : "a",
"key2" : "b"
}
@@@
# post process response (@@@ is new syntax)
# capture response to environment variables
@key1={{postjson.response.body.json.key1}}
# no need to name response in this section
@key2={{response.body.json.key2}}
# other special syntax could also be possible in this section
# e.g. save response to file (opposite syntax or reading file for request)
> ./save.response.in.file.json
# run script to post process response
@run=./postprocess.ts
###
# 2nd request that uses captured variables
GET http://httpbin.org/get?key1={{key1}}&key2={{key2}}
Hope you get the idea.
@lldata nice suggestion, script support is in my consideration, I'd like to provide some hooks(before request and after response) for user to write customize script. Add user just need to specify the script location in the request metadata like existing name metadata. For examle:
# @name sample
# @script beforeRequest ./test1.js
# @script afterResponse ./test2.js
GET https://api.example.com
I can see how you can support scripts in the comment section above the request.
Would that work for my two other examples as well?
You are getting into the developing a DSL for testing HTTP. It is very useful and if you get it right, I could imagine that other tools could pick the format up and use it as well!
I would also love the ability to set a variable from the response: e.g. @foo = {{login.response.body.$}}
That way I can have File level variables that can be overwritten by a request, and to allow a simple naming structure to more complex jsonpath queries
@eamodio this feature is in my todo list. And I am still considering the design.
@lldata @dakaraphi @eamodio @ReeganExE @itgoran I have implemented this feature and will publish in next release. The syntax would be the same as you suggested, like @foo = {{login.response.body.$}}, and you may even mix the plain text and multiple request variable references like @foo = {{login.response.body.id}}JOIN{{login.response.body.token}}
@lldata @dakaraphi @eamodio @ReeganExE @itgoran you can try the latest version 0.20.0 to verify this feature.
It works, but I could get it a little confused if I by mistake named a variable the same as a request:
# @name postjson
POST http://httpbin.org/post
{
"key1" : "a",
"key2" : "b"
}
###
@key1={{postjson.response.body.json.key1}}
@postjson={{postjson.response.body.json}}
###
# 2nd request that uses captured variables
GET http://httpbin.org/get?key1={{key1}}
###
POST http://httpbin.org/post
{{postjson}}
To reproduce run postjson request - mouseover on postjson variable in bottom of file.
The editor resolves the content of postjson correctly, but also gives a warning.

@lldata as I've mentioned in the README, the same name request variable has higher precedence over the same name file variables. So when sending request, it treats the {{postjson}} as a request variable. And the reason why {{postjson}} displays the correct request variable value is that our extension will fetch the variable value concurrently both as a request variable, file variable, and an environment. So you'd better give the file variable another name.
Nice Feature Huachao very nice!
# @name sample # @script beforeRequest ./test1.js # @script afterResponse ./test2.js GET https://api.example.com
@Huachao , script support has available?
Most helpful comment
@lldata @dakaraphi @eamodio @ReeganExE @itgoran I have implemented this feature and will publish in next release. The syntax would be the same as you suggested, like
@foo = {{login.response.body.$}}, and you may even mix the plain text and multiple request variable references like@foo = {{login.response.body.id}}JOIN{{login.response.body.token}}