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.
Environment files
Section titled “Environment files”Environments live in http-client.env.json, the same file Visual Studio and JetBrains IDEs use:
{ "$shared": { "apiVersion": "v2" }, "dev": { "baseUrl": "https://localhost:5001" }, "staging": { "baseUrl": "https://staging.example.com" }}GET {{baseUrl}}/{{apiVersion}}/orders$sharedholds values every environment uses. An environment’s own value wins over a shared one.- Reqjet uses the env files nearest to the
.httpfile: 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.
Secrets go in the private file
Section titled “Secrets go in the private file”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
{ "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.
File variables
Section titled “File variables”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 userGET {{baseUrl}}/anything/users/{{user}}Chaining requests
Section titled “Chaining requests”A request can use part of another request’s response. Name the first request with # @name, then refer to its
response:
### Sign in# @name loginPOST {{baseUrl}}/loginContent-Type: application/json
{ "user": "{{user}}", "password": "{{password}}" }
### Get my ordersGET {{baseUrl}}/ordersAuthorization: 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
loginhasn’t been sent yet, Reqjet sends it first, automatically.
Where a value comes from
Section titled “Where a value comes from”When the same name is set in several places, Reqjet uses the first it finds, in this order:
- Values a request script sets for this request (
request.variables.set). - The file’s own
@name = valuelines. - Values scripts keep for the session (
client.global.set). - The selected environment, private file first, then the shared file.
$sharedvalues.
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.
Being asked for a value
Section titled “Being asked for a value”# @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 passwordPOST {{baseUrl}}/admin/resetContent-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.