Environments and variables

An environment is a named set of variables, such as local, staging or production. Write {{baseUrl}} in a request once, and switch where it points with one shortcut.

Using variables

Write {{name}} in the URL, a query parameter, a header name or value, a form field or a JSON, XML or text body. Spaces inside the braces are allowed: {{ name }} is the same variable. When the request is sent, each marker is replaced with its value.

GET {{baseUrl}}/accounts/{{accountId}}/orders
Authorization: Bearer {{token}}

::: query
since = {{since}}
  • Every variable in the URL, the Params and Headers tables and the Body is highlighted. A variable that resolves is drawn in the accent color, and one with no value is red with a wavy underline. With no environment selected, the variables that come from an environment are red, while template functions and variables a pre-request script sets with vars.set("name", ...) stay highlighted as defined. In the tables, the chips show while the field is not being edited. Bodies larger than 1 MB are not highlighted.
  • Hover a highlighted variable to see its current value and where it comes from (the environment, or a script of this session). Values of variables whose name looks like a secret (it contains token, key, secret, password, auth or session), and any variable inside the value of a sensitive header such as Authorization, are shown as dots. Click a red variable to define it, or one that comes from the active environment to go to its row in the environment editor.
  • A variable with no value is sent literally, as {{name}}, and the response shows an Unknown variable warning. It never stops the request.
  • Variables are replaced in one pass: if the value of outer is {{inner}}, the request contains the text {{inner}}, not the value of inner.
  • A {{ with no closing }} is left alone, without a warning.
  • Inside the braces you can also call a template function, such as {{ uuid() }}.
  • Scripts are not interpolated: inside ::: pre and ::: post, read variables with vars.get() and env.get().

Autocompleting variables

In the URL, in the values of the Params, Headers and Form tables and in the fields of the Auth tab, a menu lists the variables you can insert. It opens by itself when you type {{, or with Ctrl Space anywhere in the field (Ctrl on macOS too, since ⌘ Space is Spotlight).

  • It lists the variables of the active environment, the session variables set by scripts and the names the pre-request script sets with vars.set(), each with its value shortened. Values are hidden by the same rules as in the tooltips: a name that looks like a secret, or any variable in the value of a sensitive header such as Authorization.
  • What you type after {{ filters the list, ignoring case: names that start with it come first, then names that contain it. The menu closes when nothing matches, or when you type something that cannot be part of a name, such as a space or the ( of a template function.
  • ↑ and ↓ move through the list, Enter or Tab insert the highlighted variable, and so does a click. Esc closes the menu; typing more of the name opens it again.
  • The variable is inserted as {{name}}. Inside a marker it replaces the whole marker, so {{ba}} becomes {{baseUrl}} with no extra braces. Outside one, Ctrl Space inserts it at the cursor, or in place of the selected text.
  • With no environment selected, the menu says so below the variables it can still offer.
  • In a header value, Ctrl Space outside a marker lists the usual values of that header before the variables. See suggested headers.

Environment files

Environments live in the environments/ folder at the root of the workspace. Each one is up to two files:

environments/<name>.env
The shared values: hosts, user names, feature flags. Commit it.
environments/<name>.local.env
Secrets and personal overrides: passwords, tokens, API keys. Its values win over <name>.env. Keep it out of git.
environments/staging.env
# Staging, shared by the whole team
baseUrl=https://staging.api.example.com
username=qa-bot
timeout=5000
environments/staging.local.env
password=correct-horse-battery-staple
apiKey=sk_test_51H...

The format is one KEY=value per line. Lines starting with # are comments. The value is everything after the first =, kept exactly as written: no quotes, no escaping and no trimming. The full rules are in the file format reference.

You can edit these files in any editor while Postino is open. Postino reads the active environment again every time it sends a request and when its window gets the focus back, so new values apply without reopening the workspace. An environment tab that is already open keeps the values it loaded; close and reopen it.

Keep secrets out of git

A workspace created by Postino already ignores .local.env files. Postino never edits the .gitignore of a folder you open, so add this line to it once per repository:

.gitignore
*.local.env

Switching environments

  • Click the environment pill in the title bar and choose one, or No environment.
  • Press Ctrl 1 to Ctrl 9 (⌘ on macOS) for the first nine environments, in the order of the list, and Ctrl 0 for no environment.
  • Use the Environments group of the command palette.
  • In the Environments panel, or in an environment's editor, choose Use this environment.

The active environment of each workspace is remembered and selected again when you reopen it. It is stored in Postino's configuration, not in the workspace.

Environment colors

The dot next to an environment's name gives a hint of how careful you should be. Unless you choose one, its color is Automatic: it comes from the name, ignoring case:

Name containsDotExamples
prodRedproduction, prod-eu
stag, test, qa or uatAmberstaging, test, qa2, uat
Anything elseGreenlocal, dev, docker
No environmentHollow ring

To choose another color, open the environment and click the dot next to its name, or choose Color… in its More actions menu. Pick one of the nine colors (red, orange, amber, green, teal, blue, violet, pink and grey), or Automatic to go back to the color of the name. The color shows everywhere the environment does: the panel, the editor, the environment picker and the command palette.

The choice is saved in the workspace configuration, .postino/project.toml, under [environments.colors], with the color's English name in lowercase (prod = "violet"), so everyone who uses the workspace sees the same colors. The file is created the first time you choose a color. A color name Postino does not know is ignored, and the environment keeps its automatic color.

Resolution order

When Postino replaces {{name}}, it looks in these layers and uses the first one that has the variable:

  1. Pre-request variables. Set with vars.set() by the pre-request script of this run. They exist only for this one send.
  2. Session variables. Set with env.set() by any script since Postino started. They are shared by every request and disappear when you quit.
  3. .local.env of the active environment.
  4. .env of the active environment.

If no layer has it, the variable is unknown. A disabled entry is skipped as if it were not there. If a file defines the same name twice, the first definition is the one used.

Variables built from other variables

The value of an environment variable can use other variables, with the same {{name}} markers as a request, and add text around them. Define a part once and build the rest from it:

environments/staging.env
host=staging.api.example.com
baseUrl=https://{{host}}
usersUrl={{baseUrl}}/v2/users
basicAuth={{ base64Encode(credentials) }}
credentials={{username}}:{{password}}

A request that uses {{usersUrl}} sends https://staging.api.example.com/v2/users. The order of the lines does not matter, and a reference can go through several variables.

  • The names inside a value are looked up in every layer of the resolution order, so a session or pre-request variable wins there too. When a script sets baseUrl with env.set(), usersUrl follows it.
  • Template functions work inside a value, and a composed variable can be the argument of one, as credentials above.
  • A name that no layer has stays as written, {{name}}, and is reported as an unknown variable, like in a request.
  • A value that leads back to its own variable, such as a={{b}} and b={{a}}, stops there: the marker stays as written and the response shows the warning circular variable reference: a -> b -> a.
  • Only the values of the environment files are expanded. A value set by a script, with env.set() or vars.set(), is used exactly as given, and env.get() returns the value as written in the file, markers included.
  • The tooltip of a variable in the request editor shows the expanded value, the one that is sent.

The environment editor

Click an environment in the Environments panel to open it in a tab.

The environment editor: the staging variables, two of them stored in the gitignored local file and masked. The environment editor: the staging variables, two of them stored in the gitignored local file and masked.
  • Files. The header shows the two files of the environment, marked versioned (.env) and gitignored (.local.env), or not created when a file does not exist yet.
  • Scope. All shows the merged view: every variable once, with the .local.env value where it overrides .env, plus the session variables. Or pick one file to see only its rows.
  • Stored in. Each variable shows the file it lives in. The Move to the other file button moves it between .env and .local.env in one click. A .local.env row that hides a .env value says Overrides the value in ….
  • Secrets. Values stored in .local.env are masked. Show secrets reveals them.
  • Session values. Variables set by scripts during this session are listed as session, with the note Set by a script · cleared on quit.
  • Filter narrows the list by name. Add variable adds a row to .env, and the remove button deletes a row.
  • Press Ctrl S to save. Closing a tab with unsaved changes asks first.

Saving rewrites only the lines you changed: comments, blank lines and the order of everything else stay as they were. The .local.env file is created when you first store a variable in it.

Saving is refused, with a message, when a row has a value but no name, a name contains = or a line break or starts with #, a value contains a line break, or the same name appears twice in one file.

Environment actions

The More actions menu of the editor has:

  • Color…, which opens the color picker.
  • Move up and Move down, which move the environment one place in the order. Alt ↑ and Alt ↓ (⌥ on macOS) do the same while the environment's tab is the active one.
  • Rename, which renames both files.
  • Duplicate, which copies both files as <name> copy (<name> copy 2 and so on when that name is taken), right after the original and with its color. The word copy follows the language of Postino. It copies what is saved on disk: unsaved edits stay in the tab.
  • Reveal in file manager, which opens the environments/ folder.
  • Delete, which removes both .env and .local.env after asking. It cannot be undone.

Right click an environment in the Environments panel for the same actions without opening it: Open, Use this environment (disabled on the active one), Color (a submenu with Automatic and the nine colors, the current one checked), Move up, Move down, Rename, Duplicate, Copy path, Copy relative path, Show in file manager and Delete. They act on the environment you right clicked, whatever tab is active. No environment has no menu. Right click the empty part of the panel for New environment. While the Environments panel is shown, Shift F10 (or the Menu key on Linux and Windows) opens this menu for the environment open in the active tab, under its row.

Order

Environments are listed in alphabetical order until you change it. Drag an environment in the Environments panel by the grip that appears at the left of its row when you point at it: a line shows where it lands. Drop it on No environment to make it the first, or below the list to make it the last. No environment always stays at the top.

The order applies everywhere environments are listed: the panel, the environment picker of the title bar, the command palette and the Ctrl 1 to Ctrl 9 shortcuts. It is saved in the workspace configuration, .postino/project.toml, so it is shared with everyone who uses the workspace through git. The file is created the first time you reorder. An environment that is not in the saved order, such as a new one, goes after the others, in alphabetical order.

Creating an environment

  1. Open the Environments panel from the activity rail.
  2. Click New environment, type a name and press Enter.
  3. Postino creates environments/<name>.env, creating the folder if needed, and you can start adding variables.

You can also create the files by hand in any editor. An environment exists as soon as its .env file does, and Postino lists it when its window gets the focus back.

Defining a variable from a request

Click a variable chip in the URL bar or in a table, or Define on the Unknown variable warning of the response. A red chip has no value yet; a chip that resolves takes you to its definition, unless its value comes from a script, which has no row to show. Where you land depends on the active environment:

  • No environment is active: the Environments panel opens in the sidebar. Make an environment active (open it and click Use this environment, or choose it in the environment picker of the title bar), or create one with New environment, then click the variable again.
  • The active environment does not have the variable: its tab opens with a new row for it at the end of the table, and the cursor in the value. The row goes to .local.env (not versioned) when the name looks like a secret, that is, when it contains token, secret, password or key, ignoring case. Otherwise it goes to .env. You can change it in the Stored in column.
  • The active environment already has the variable: its tab opens, scrolled to that row, with the cursor in the value. No row is added. When the variable is in both files, that is the .local.env row, the one that applies.

Type the value and save the tab with Ctrl S: nothing is written before that, and the chip stays red until the variable is saved. When the response warning lists several unknown variables, Define adds a row for each one and puts the cursor in the first.

Right click a variable, in a chip, in a field you are editing or in the request body, for two more entries after the usual editing ones:

  • Copy value copies the whole value of the variable, as it resolves now. It is disabled when the variable has no value yet, or when its value is hidden because its name looks like a secret.
  • Edit in environment does what a click on the chip does, as described above. It is disabled for a variable that a script or the session sets.

Session variables

A post-response script can store a value for later requests with env.set(). The typical case is a login request that keeps the token:

env.set("token", res.json().access_token);

Session variables:

  • take priority over both environment files;
  • are shared by every request until you quit Postino;
  • are never written to an .env file;
  • show in the environment editor as session;
  • can be removed with env.unset("token").

To keep a value across restarts, copy it into the environment in the editor.

Request variables

A pre-request script can set a variable for the current send only, with vars.set(). It has the highest priority and is gone when the run ends:

POST {{baseUrl}}/payments
Idempotency-Key: {{requestId}}

::: pre
vars.set("requestId", util.uuid());

Postino recognizes vars.set("name", …) calls with a literal name in the pre-request script, so those variables are not flagged as unknown in the URL bar before you send.

Found a mistake? Edit this page on GitHub or open an issue.

↑↓to move ↵to open /or Ctrl Kto search from any page