Vscode-restclient: How do I use env variables?

Created on 15 Jan 2020  路  4Comments  路  Source: Huachao/vscode-restclient

I'm sorry for the question but I haven't really figured out how to use the environment variables.

I have an "api.http" file with the requests, and a "env.http" file with the variables, but I can't make it work.

Can you please explain me how to do this?

Thanks

Most helpful comment

hey Gjoforte,

You can add "rest-client.environmentVariables" to Vscode user setting or to Vscode workspace file (".code-workspace")

  1. For user setting: press ctr + shift + p => open setting (JSON).
  2. For workspace : File-> 'save workspace as' or edit existing one.

In the Json file , under setting add the _restCleint.code-workspace_ env config.
after saving it, press F1 and search for Rest Client: Switch Environment , you should be able to see the environments.

hope you will find it useful.

i.e:

**"settings": {
    "rest-client.environmentVariables": {
        "$shared": {
            "version": "v1",
            "prodToken": "foo",
            "nonProdToken": "bar"
        },
        "local": {
            "version": "v2",
            "host": "https://www.cnn.com",
            "token": "{{$shared nonProdToken}}",
            "secretKey": "devSecret"
        },
        "production": {
            "host": "example.com",
            "token": "{{$shared prodToken}}",
            "secretKey" : "prodSecret"
        }
    }
       **

Regards,
Eran

All 4 comments

hey Gjoforte,

You can add "rest-client.environmentVariables" to Vscode user setting or to Vscode workspace file (".code-workspace")

  1. For user setting: press ctr + shift + p => open setting (JSON).
  2. For workspace : File-> 'save workspace as' or edit existing one.

In the Json file , under setting add the _restCleint.code-workspace_ env config.
after saving it, press F1 and search for Rest Client: Switch Environment , you should be able to see the environments.

hope you will find it useful.

i.e:

**"settings": {
    "rest-client.environmentVariables": {
        "$shared": {
            "version": "v1",
            "prodToken": "foo",
            "nonProdToken": "bar"
        },
        "local": {
            "version": "v2",
            "host": "https://www.cnn.com",
            "token": "{{$shared nonProdToken}}",
            "secretKey": "devSecret"
        },
        "production": {
            "host": "example.com",
            "token": "{{$shared prodToken}}",
            "secretKey" : "prodSecret"
        }
    }
       **

Regards,
Eran

@emgood thanks for your reply, @gjoforte you can follow the instructions from @emgood

hi all,
how does it know which environment you are running in? e.g "local" or "production".
Where do you set this?

Thanks

oh I found the it in the documentation. thank you for this great extension Huacho.

"Currently, active environment's name is displayed at the right bottom of Visual Studio Code, when you click it, you can switch environment in the pop-up list. "

Was this page helpful?
0 / 5 - 0 ratings