Dynamic Templates
Generate realistic test data dynamically using dotMock's built-in template functions.
dotMock uses Go templates to generate dynamic data. All template functions are available using the
{{functionName}} or {{functionName(args)}} syntax.Basic Syntax
Use double curly braces to insert template expressions in your JSON responses:
{
"id": "{{uuid}}",
"name": "{{randomName}}",
"email": "{{randomEmail}}",
"age": {{randomInt(18, 65)}},
"joinedAt": "{{date('-1y')}}"
}Pro tip: Template expressions are evaluated every time the endpoint is called, generating fresh data for each request!
Common Template Functions
Person Functions
{{randomName}}→ "John Smith"{{randomEmail}}→ "[email protected]"{{randomPhone}}→ "+1-555-123-4567"{{randomPhone('UK')}}→ "+44-7-1234-5678"{{randomCompany}}→ "Tech Solutions Inc"{{randomAddress}}→ "123 Main St, New York, NY 10001"Advanced Usage
Function Arguments
Many template functions accept arguments to customize the output:
{{randomInt(100, 999)}}Generates an integer between 100 and 999{{lorem(5)}}Generates exactly 5 lorem ipsum words{{randomString(16)}}Generates a random string of 16 characters{{randomChoice('active', 'inactive', 'pending')}}Randomly selects one value from the provided optionsDate Offsets
The date function supports relative time offsets:
+1d - Tomorrow-1d - Yesterday+1w - Next week-1w - Last week+1m - Next month-1m - Last month+1y - Next year-1y - Last yearComplete Example
Here's a comprehensive example using various template functions:
{
"users": [
{
"id": "{{uuid}}",
"profile": {
"name": "{{randomName}}",
"email": "{{randomEmail}}",
"phone": "{{randomPhone}}",
"avatar": "https://avatars.githubusercontent.com/u/{{randomInt(1000, 9999)}}",
"bio": "{{lorem(15)}}"
},
"address": "{{randomAddress}}",
"company": "{{randomCompany}}",
"subscription": {
"plan": "{{randomChoice('free', 'pro', 'enterprise')}}",
"status": "{{randomChoice('active', 'cancelled', 'expired')}}",
"expiresAt": "{{date('+1y')}}"
},
"stats": {
"loginCount": {{randomInt(1, 1000)}},
"lastLogin": "{{date('-3d')}}",
"isVerified": {{randomBool}},
"rating": {{randomFloat(1, 5)}}
},
"createdAt": "{{date('-1y')}}",
"updatedAt": "{{now}}"
}
],
"meta": {
"total": {{randomInt(50, 500)}},
"page": 1,
"perPage": 10,
"timestamp": "{{now}}"
}
}Fun Functions
We also include some fun functions for testing:
{{animal.dog}}→ Returns a random dog breed like "Golden Retriever"{{animal.cat}}→ Returns a random cat breed like "Persian"Quick Reference
Identifiers & Numbers
uuidrandomInt(min, max)randomFloat(min, max)number.int
Person & Business
randomNamerandomEmailrandomPhonerandomCompanyrandomAddress
Random & Utilities
randomBoolrandomChoice(...)randomString(length)lorem(words)
Date & Time
nownow(format)date(offset)date(offset, format)
Animals
animal.doganimal.cat
All template functions are processed server-side using Go templates. The data is generated fresh for each request, ensuring realistic and varied test data.