Huachao / vscode-restclient

REST Client Extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=humao.rest-client
MIT License
5.31k stars 444 forks source link

setting shared variables #402

Open rockaut opened 5 years ago

rockaut commented 5 years ago

Currently we can set local/file/request variables with

@authToken = {{login.response.body.token}}

It would be great if we could also set shared/environment variables. Maybe like:

@shared.authToken = {{login.response.body.token}}

Or maybe something like a session variables which will persist the whole session. This way we would only need to run a login request just once.

fstof commented 5 years ago

Agreed. This is especially useful if requests are split across different files. we won't need to do a login on each file

I suggest adjusting the title of this issue to also mention "environment variables"

My take on a possible syntax would be For normal environment variables: $currentEnv.authToken = {{login.response.body.token}} For shared variables: $shared.authToken = {{login.response.body.token}}

The reason for splitting specifically between shared and normal environment vars is that we want the token be persisted for each environment. If I switch i know the token will follow.

Naturally this applies to any variable... not just a token :-)

Harag9 commented 5 years ago

I'm just starting out with Rest Client, and moving from postman. having a lot of quests means I need to scroll up and down all the time to run them, so would prefer to break them into groups of file, but because I can't share the token between the files, I'm having to "login" on each file to get the token.

I can't find a way to update the Environment variable I have in my VSCode settings file to make it "global" - so this would be a great addition - Any news on this?

FloMaetschke commented 4 years ago

I have a folder structure by feature, each feature has a controller with its functions and etc. stuff in it. It also has a e.g. auth.http in the auth folder, or a users.http in the users folder. At the moment, i have to copy the login request to all http files in all folders, to login file by file. thats really annoying.