Environments
Common Variables: The following variables are available for all requests: {{request_name}}, {{collection_name}}, and {{folder_name}}.
The following environments can be used in Thunder Client, ranked from least to highest precedence:
- OS Environment Variables:
You can reference OS environment variables as global variables using the format{{variable}}. - *Global Environment:
Global Environment allows you to store variables that can be accessed across all collections. These values are saved in thetc_env_global.jsonfile (refer to the image above, option 2). - *Local Environment:
You can use Local Environment to save secrets and transient tokens locally on your computer; useful for excludingsecretsfrom a Git project. This environment is aglobaltype, and the variables are available to all collections (refer to the image above, option 3). - *env files:
You can use.envfiles in Thunder Client. To use a.envfile, follow the steps below:- Create an Environment (using option 1 in the image above).
- Open the Environment view, where you will see the option
Link to .env file. - Select the
.envfile and save it. Now you can use the variables in Requests using{{variable}}. - The variables in the
.envfile should use this format:
.env.samplekey=value name=thunder number=25543 - Active Environment:
To use an environment’s variables, you need to make it active using the options menu..., then selectSet Active. - Attach Env to Collection (Optional):
You can attach an environment to a collection from the Collection Settings view. Use this option when you want to link multiple collections to multiple environments. The values in this environment take precedence over the active environment. If you change environments frequently, this option is not recommended. See the example below:CollectionA -> EnvA CollectionB -> EnvB CollectionC -> EnvC - *Collection and Request Variables
- You can set
collection- andrequest-specific env variables in scripting using therequestscope.- These variable values are available during the execution of the request only.
- To use this, open collection settings or the request view, then select the
Pre Runtab and use theScriptingtab.
tc.setVar("name", "Thunder Client", "request");
tc.setVar("baseUrl", "http://localhost:8744", "request");* These features are available only in the paid version.
How to Use Environment Variables
- To use environment variables, use the
{{variableName}}format. You can use variables in Query Params, Headers, Body, and Tests.
Import .env files
This feature is available only in the paid version.
- You can import Thunder Client, Postman, and
.envfiles using the Import menu option (see the image above, option 4). More details here.
Set Environment Variable
- Setting environment variables is supported in the
Teststab using the UI and scripting. - Please see the documentation here.
Last updated on