vscode-restclient
vscode-restclient copied to clipboard
Reference named request variables crossing .http file
Suppose there are 3 http files including different api, and all api use the same dynamic auth token.
- auth.http
- shopping.http
- eating.http
- housing.http
The token will expired, so we use request variables, like:
# @name auth
POST http://{{auth_host}}/api/v1/tokens
Content-Type: application/json
{
"user": {{auth_user}},
"key": "{{auth_key}}",
"ttl" : 3600
}
@auth_token = {{auth.response.body.$.token}}
In shopping.http, eating.http, housing.http
, all api have to use auth_token
as header to send requests, likes:
### in shopping.http
GET http://{{server_host}}/api/v1/shopping/items?_num=-1
Content-Type: application/json
X-Auth-Token: {{auth_token}}
### in eating.http
GET http://{{server_host}}/api/v1/eating/restaurants?_num=-1
Content-Type: application/json
X-Auth-Token: {{auth_token}}
Now, we have to define the @name auth
request and @auth_token = {{auth.response.body.$.token}}
variable in every http files.
Question: Can we just define the @name auth
request and @auth_token = {{auth.response.body.$.token}}
variable in one http file such as auth.http
, and reference these variables in other http files?
@Huachao
I am very interested in such feature. I would love to be able to set up token auth request in one place, and then link to it throughout the other files in the workspace. If somehow possible to require the token automatically, would be even more amazing.
Potentially related to:
- https://github.com/Huachao/vscode-restclient/issues/1076
- https://github.com/Huachao/vscode-restclient/issues/943
- https://github.com/Huachao/vscode-restclient/issues/845
- https://github.com/Huachao/vscode-restclient/issues/713
- https://github.com/Huachao/vscode-restclient/issues/570
I would be very interested in seeing this functionality come to light. It's annoying to have to do my auth in every file.
Looking forward to having this functionality shipped.
+1
Can't wait to use this