Skip to content

Variables

Variables are defined directly in the .http file using the @ prefix:

@hostname = api.example.com
@port = 8080
@baseUrl = https://{{hostname}}:{{port}}
Universal Supported identically by all major implementations.

The @name = value syntax is supported by all major implementations. Variables can reference other variables in their definitions.

Variable names must not contain spaces. VS Code REST Client requires a complete line per definition with whitespace trimmed.

httpyac

httpyac introduces a distinction between fixed variables (evaluated at parse time, using =) and lazy variables (evaluated at execution time, using :=):

@eager = {{$timestamp}}
@lazy := {{$timestamp}}

The eager variable captures the timestamp once when the file is parsed. The lazy variable generates a fresh timestamp each time it's used.

All implementations use double curly braces for variable substitution:

GET https://{{hostname}}/api/{{version}}/users
Authorization: Bearer {{token}}
Universal Supported identically by all major implementations.

The {{variableName}} syntax is universal.

VS Code

VS Code REST Client supports {{%variableName}} which URL-encodes the variable value before substitution.

Variable resolution order differs between implementations:

VS Code REST Client (highest to lowest):

  1. Request variables (named request responses)
  2. File variables (@var = value)
  3. Prompt variables (@prompt)
  4. Environment variables (from settings.json)

JetBrains (highest to lowest):

  1. Per-request variables (set in pre-request scripts)
  2. In-place file variables (@var = value)
  3. Global variables (client.global.set())
  4. Environment variables (from http-client.env.json)

httpyac (highest to lowest):

  1. Request-scoped variables
  2. File-global variables
  3. Environment variables (from .env, http-client.env.json, or config files)

Named request variables (response chaining)

Section titled “Named request variables (response chaining)”

Responses from named requests can be referenced as variables. The syntax differs significantly between implementations.

VS Code REST Client
# @name login
POST https://api.example.com/auth
Content-Type: application/json

{"username": "admin", "password": "secret"}

###
GET https://api.example.com/protected
Authorization: Bearer {{login.response.body.$.token}}
JetBrains
POST https://api.example.com/auth
Content-Type: application/json

{"username": "admin", "password": "secret"}

> {%
client.global.set("auth_token", response.body.token);
%}

###
GET https://api.example.com/protected
Authorization: Bearer {{auth_token}}
httpyac
# @name login
POST https://api.example.com/auth

###
# @ref login
GET https://api.example.com/protected
Authorization: Bearer {{login.token}}

VS Code REST Client uses dot-path notation with these reference patterns:

  • {{name.response.body.$.jsonPath}} — JSONPath into JSON response
  • {{name.response.body.//xpathExpr}} — XPath into XML response
  • {{name.response.body.*}} — entire response body
  • {{name.response.headers.Header-Name}} — response header value
  • {{name.request.body.*}} — original request body

JetBrains uses response handler scripts to store values in global variables, then references them as {{variableName}}. There is no direct dot-path syntax.

httpyac supports the # @name / # @ref pattern, where a named request's parsed response body becomes available as a variable.

Visual Studio 2022 (since v17.12) supports VS Code REST Client-style request variables.

Feature VS CodeJetBrainshttpyacVS 2022kulala
Inline variable definition (@var = value)
Variable substitution ({{variableName}})
Percent-encoding substitution ({{%var}}) URL-encodes the variable value. Unique to VS Code REST Client.
Lazy variables (@var := value) Evaluated at execution time rather than parse time.
Named request response chaining Syntax differs: VS Code uses dot-path ({{name.response.body.$.path}}), JetBrains uses script-based global variables, httpyac uses @ref.
Environments in settings.json
http-client.env.json
http-client.private.env.json
http-client.env.json.user Microsoft-specific override file.
.env dotenv files VS Code REST Client and VS 2022 support via {{$dotenv NAME}} accessor. httpyac and kulala parse .env files natively.
JS/JSON config file httpyac.config.js or .httpyac.js
$shared environment
Secrets providers (Azure Key Vault, etc.) ASP.NET Core User Secrets, Azure Key Vault, DPAPI.