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

Reference named request variables crossing .http file

Open junyicc opened this issue 1 year ago • 8 comments

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

junyicc avatar Apr 28 '23 08:04 junyicc

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.

bojanpikl avatar May 08 '23 08:05 bojanpikl

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

felipemullen avatar Jun 27 '23 18:06 felipemullen

I would be very interested in seeing this functionality come to light. It's annoying to have to do my auth in every file.

calloncampbell avatar Oct 25 '23 04:10 calloncampbell

Looking forward to having this functionality shipped.

IbsenFahir avatar Feb 19 '24 19:02 IbsenFahir

+1

amjadbouhouch avatar Jul 07 '24 12:07 amjadbouhouch

Can't wait to use this

hidaytrahman avatar Jul 27 '24 07:07 hidaytrahman