Skip to main content
hitspec provides 17 built-in functions that generate dynamic values at runtime. Call them inside double curly braces with the $functionName(args) syntax.
POST {{baseUrl}}/users
Content-Type: application/json

{
  "id": "{{$uuid()}}",
  "name": "User {{$random(1, 9999)}}",
  "email": "{{$randomEmail()}}",
  "createdAt": "{{$now()}}"
}

Identity and Randomness

$uuid()

Generates a random UUID v4 string.
X-Request-Id: {{$uuid()}}
Returns: string — e.g., 550e8400-e29b-41d4-a716-446655440000

$random(min, max)

Generates a random integer between min and max (inclusive). Defaults to 0-100 when called without arguments.
ParameterTypeDefaultDescription
mininteger0Minimum value (inclusive)
maxinteger100Maximum value (inclusive)
{
  "quantity": {{$random(1, 10)}},
  "score": {{$random(0, 100)}}
}
Returns: integer

$randomString(length)

Generates a random string of mixed-case alphanumeric characters.
ParameterTypeDefaultDescription
lengthinteger16Length of the generated string
{
  "password": "{{$randomString(32)}}"
}
Returns: string — e.g., aB3kL9mNpQ7rS2tU

$randomAlphanumeric(length)

Generates a random alphanumeric string. Functionally identical to $randomString.
ParameterTypeDefaultDescription
lengthinteger8Length of the generated string
Returns: string

$randomEmail()

Generates a random email address.
{
  "email": "{{$randomEmail()}}"
}
Returns: string — e.g., abcdefgh@klmnop.com

Date and Time

$now()

Returns the current UTC date and time in RFC 3339 format.
{
  "createdAt": "{{$now()}}"
}
Returns: string — e.g., 2026-02-09T15:04:05Z

$timestamp()

Returns the current Unix timestamp in seconds.
X-Timestamp: {{$timestamp()}}
Returns: integer — e.g., 1707490800

$timestampMs()

Returns the current Unix timestamp in milliseconds.
{
  "sentAt": {{$timestampMs()}}
}
Returns: integer — e.g., 1707490800000

$date(format)

Returns the current UTC date formatted with a custom Go time layout. Defaults to 2006-01-02 (ISO date).
ParameterTypeDefaultDescription
formatstring2006-01-02Go reference time layout
{
  "date": "{{$date()}}",
  "datetime": "{{$date(2006-01-02T15:04:05Z)}}"
}
Returns: string — e.g., 2026-02-09
Go time layouts use the reference date Mon Jan 2 15:04:05 MST 2006. For example, {{$date(2006-01-02)}} produces 2026-02-09, and {{$date(01/02/2006)}} produces 02/09/2026.

Encoding and Hashing

$base64(value)

Base64-encodes the given string.
ParameterTypeDescription
valuestringString to encode
Authorization: Basic {{$base64(admin:secret)}}
Returns: string — e.g., YWRtaW46c2VjcmV0

$base64Decode(value)

Decodes a Base64-encoded string.
ParameterTypeDescription
valuestringBase64 string to decode
Returns: string — Returns empty string on decode error.

$md5(value)

Returns the MD5 hex digest of the given string.
ParameterTypeDescription
valuestringString to hash
{
  "checksum": "{{$md5(file-contents)}}"
}
Returns: string — 32-character hex string

$sha256(value)

Returns the SHA-256 hex digest of the given string.
ParameterTypeDescription
valuestringString to hash
Returns: string — 64-character hex string

$urlEncode(value)

URL-encodes the given string (percent-encoding).
ParameterTypeDescription
valuestringString to encode
GET {{baseUrl}}/search?q={{$urlEncode(hello world)}}
Returns: string — e.g., hello+world

$urlDecode(value)

URL-decodes a percent-encoded string.
ParameterTypeDescription
valuestringURL-encoded string to decode
Returns: string — Returns the original string on decode error.

Utilities

$json(value)

Passes through the value as-is. Useful for embedding raw JSON strings in variable interpolation contexts.
ParameterTypeDescription
valuestringJSON string to pass through
Returns: string

$env(name, default)

Reads a system environment variable. Returns the optional default value if the variable is not set or empty.
ParameterTypeDefaultDescription
namestring(required)Environment variable name
defaultstring""Fallback value
@token = {{$env(API_TOKEN)}}
@dbUrl = {{$env(DATABASE_URL, sqlite://./test.db)}}
Returns: string
Use $env() to keep secrets out of your test files. Store API tokens, passwords, and connection strings in environment variables and reference them with {{$env(VAR_NAME)}}.

Quick Reference Table

FunctionArgumentsDefault ArgsReturns
$now()RFC 3339 datetime
$timestamp()Unix seconds
$timestampMs()Unix milliseconds
$uuid()UUID v4 string
$random(min, max)min, max0, 100Random integer
$randomString(len)length16Random string
$randomAlphanumeric(len)length8Random string
$randomEmail()Random email
$base64(val)valueBase64 encoded
$base64Decode(val)valueDecoded string
$md5(val)valueMD5 hex digest
$sha256(val)valueSHA-256 hex digest
$urlEncode(val)valueURL-encoded string
$urlDecode(val)valueURL-decoded string
$date(fmt)format2006-01-02Formatted date
$json(val)valuePassthrough string
$env(name, def)name, defaultEnv var value