Get started · Lesson 2 of 20
Environments and variables
Write {{baseUrl}} once, switch servers with one click and keep secrets on your device.
Typing https://staging.example.com into every request is slow, and changing it later is worse. A variable is a name that stands for a value: write {{baseUrl}}/users and Swastik Codes swaps in the real address when it sends. An environment is a named set of variables, such as Local, Staging and Production, so switching servers is one click.
Create an environment
- In the left sidebar, open Environments and click + (or use the environment menu at the top right and choose New environment).
- Name it Staging.
- Add a variable: name
baseUrl, initial valuehttps://httpbin.org. - Make a second environment, Local, with
baseUrlset tohttp://localhost:8000.
Use the variable
In a request URL, type {{baseUrl}}/get. As you type {{, the editor suggests the variables it knows. Pick Staging in the environment menu at the top right and send: the request goes to httpbin. Pick Local and the same request goes to your own machine.
Hover over {{baseUrl}} to see its value and where it comes from. A variable nothing defines is shown in red, so typos show up before you send.
Initial value and current value
Every variable has two values:
- The initial value is shared: it syncs to your team in cloud workspaces and is included when you export.
- The current value stays on this device. Use it for your own password or token, so it is never shared.
When a current value is set, it wins. Leave it empty to use the initial value.
Keep secrets secret
Set a variable's type to secret and its value is masked on screen and never written into exports or published docs. For the strongest protection, put credentials in the vault instead and refer to them as {{vault:stripe_key}}: vault secrets are encrypted on your device and can be limited to the domains they belong to.
Where variables can live
From the widest to the narrowest:
- Globals: available everywhere in the workspace.
- Collection variables: shared by every request in a collection (open the collection, Variables tab).
- Environment variables: the ones you switch.
- Folder variables and data file columns in the runner.
If the same name exists in several places, the narrowest one wins. Scripts can also set variables, for example to keep a login token; you will do that in the testing lessons.
Built-in random values
Names that start with $ are generated on every send: {{$guid}}, {{$timestamp}}, {{$randomEmail}}, {{$randomInt}} and many more. Use them to create test data that never collides.
What you learned
{{name}}stands for a value; environments let you switch whole sets of values.- Initial values are shared, current values stay on your device, and secrets belong in secret variables or the vault.
Next: organise requests in a collection and set up sign-in once for all of them.