Skip to content

Environments and variables

A variable is a value written as {{name}} in a URL, header or body. An environment is a set of values, such as dev, staging and production. You pick the environment at the top right of the window, and every request uses its values.

Environments live in http-client.env.json, the same file Visual Studio and JetBrains IDEs use:

http-client.env.json
{
"$shared": {
"apiVersion": "v2"
},
"dev": {
"baseUrl": "https://localhost:5001"
},
"staging": {
"baseUrl": "https://staging.example.com"
}
}
GET {{baseUrl}}/{{apiVersion}}/orders
  • $shared holds values every environment uses. An environment’s own value wins over a shared one.
  • Reqjet uses the env files nearest to the .http file: in its folder, or the closest parent folder that has them. So one set of env files at the top of a repository covers every folder below it.
  • The Environments tab lists every environment and its values, and edits them.

Tokens, passwords and API keys belong in the private env file, http-client.env.json.user, which sits beside http-client.env.json and isn’t committed. Its values override the shared file’s, one by one:

  • Directoryapi/
    • http-client.env.json shared with the team (commit it)
    • http-client.env.json.user your secrets (never commit it)
    • orders.http
http-client.env.json.user
{
"dev": {
"apiKey": "sk_test_…"
}
}

JetBrains’ private file, http-client.private.env.json, is read too. When both exist, the .user file wins.

When Reqjet finds a private env file in a git repository that isn’t ignoring it, it offers (once per repository) to add it to .gitignore. Choose Don’t ask again if the file is meant to be committed, for example because it only holds demo values.

A file can set its own values at the top, which every request in that file can use:

@baseUrl = https://httpbin.org
@user = ada
### Get the user
GET {{baseUrl}}/anything/users/{{user}}

A request can use part of another request’s response. Name the first request with # @name, then refer to its response:

### Sign in
# @name login
POST {{baseUrl}}/login
Content-Type: application/json
{ "user": "{{user}}", "password": "{{password}}" }
### Get my orders
GET {{baseUrl}}/orders
Authorization: Bearer {{login.response.body.$.token}}
  • {{login.response.body.$.token}} picks a value out of the JSON body with a JSONPath.
  • {{login.response.headers.Location}} reads a response header.
  • {{login.request.body.$.user}} reads what was sent.
  • If login hasn’t been sent yet, Reqjet sends it first, automatically.

When the same name is set in several places, Reqjet uses the first it finds, in this order:

  1. Values a request script sets for this request (request.variables.set).
  2. The file’s own @name = value lines.
  3. Values scripts keep for the session (client.global.set).
  4. The selected environment, private file first, then the shared file.
  5. $shared values.

On the command line, --var name=value overrides all of them. The response’s Variables tab shows the value each variable had and where it came from.

Reqjet also has built-in values such as {{$uuid}}, {{$timestamp}} and {{$randomInt 1 100}}. See Built-in variables.

# @prompt asks for a value each time the request is sent, which suits values you don’t want to save anywhere:

### Reset a password
# @prompt email The account's email address
# @prompt password
POST {{baseUrl}}/admin/reset
Content-Type: application/json
{ "email": "{{email}}", "password": "{{password}}" }

Names such as password, token or secret are masked as you type and never offered again. Other answers are offered as the default next time.