Variable Definition
Define variables using the@ prefix followed by the variable name, an equals sign, and the value:
Examples
Variable Definitions
Variable definitions should appear before the requests that use them.
Variable Reference
Reference variables in your requests using double curly braces:In URLs
URL Variables
In Headers
Header Variables
In Request Bodies
Body Variables
Complete Example from Specification
Here’s the full example from the HTTPSpec specification document:Complete Variable Example
Use Cases
Authentication Tokens
Authentication Tokens
Define your auth token once and use it across multiple requests:
Environment-Specific URLs
Environment-Specific URLs
Switch between development, staging, and production:
Shared Test Data
Shared Test Data
Implementation Status
Planned Features
According to the HTTPSpec specification, future versions may support:- Response variable extraction - Capture values from responses and use them in subsequent requests
- Environment variables - Reference system environment variables in test files
- Computed variables - Variables with dynamic values based on expressions
Current Workarounds
Until variable substitution is implemented, you can:- Use environment variables in your shell and process files with
envsubstbefore running HTTPSpec - Use templating tools to generate
.httpfiles from templates - Hard-code values directly in your test files
envsubst Example
Syntax Reference
| Syntax | Purpose | Status |
|---|---|---|
@var = value | Define a variable | Planned |
{{var}} | Reference a variable | Planned |
@var = ${ENV_VAR} | Environment variable | Future |
| Response extraction | Capture from responses | Future |
Related Documentation
Request Format
Learn the complete HTTP request syntax
Assertions
How to validate responses with assertions