Defining Variables
Use the@variable = value syntax at the top of a .http file:
Interpolation
Reference variables anywhere in your requests using double curly braces:- URLs
- Headers
- Request bodies
- Query parameters
- Assertion values
- Other variable definitions
- Metadata directive arguments
Built-in Functions
hitspec provides 17 built-in functions that generate dynamic values at runtime. Call them with the$functionName() syntax inside double curly braces.
Identity and Randomness
Date and Time
The
$date() function uses Go’s reference time layout. The reference date is Mon Jan 2 15:04:05 MST 2006. For example, {{$date(2006-01-02)}} produces 2024-01-18.Encoding and Hashing
Utilities
Practical Examples
- Unique test data
- Authentication headers
- URL construction
System Environment Variables
Access system environment variables with$env():
hitspec.yaml environments using
shell-style ${VAR} syntax:
Capture References
When a request captures values from its response, subsequent requests can reference them using the{{requestName.captureName}} pattern:
Variable Resolution Order
When the same variable name is defined in multiple places, hitspec resolves it in this order (later sources override earlier ones):- hitspec.yaml environments — values from the
environmentssection for the active--env - Inline variables —
@variable = valuein the.httpfile - Captured values —
{{requestName.captureName}}from prior responses
$uuid(), $timestamp(), $env(), …) and system variables ({{$VAR}}) are evaluated wherever they appear.
Variable Scope
Variables defined with@variable = value are scoped to the file in which they appear. Every request in that file can reference them.
Captured variables are scoped to the entire test run. Any request in any file can reference a captured value, as long as the capturing request has already executed (enforced by @depends).
Environment variables (from the environments section of hitspec.yaml) are global and available to all files in the test run.