Custom mock
1.
2.
Customize Specific Fields
How to Set Custom Field Values
1. Directly Input Values
2. Use Faker.js Dynamic Values
{{$category.method}}
{{$person.fullName}}
, results like Rachel Wheeler
{{$internet.email}}
, results like Arno.Huels33@yahoo.com
{{$commerce.productName}}
, results like Elegant Plastic Bike
3. Use Faker Methods With Parameters
For example:
{{$number.int(min=0,max=10000)}}
{{$phone.number(style='human')}}
{{$number.int(multipleOf=3)}}
{{$helpers.arrayElement(['red','blue','green'])}}
{{$date.between(from='2024-01-01',to='2024-12-31',format='yyyy-MM-dd')}}
4. Concatenate Multiple Dynamic Expressions (Generate a Full Address Example)
{{$location.streetAddress}}, {{$location.city}}, {{$location.state}}, {{$location.zipCode}}, {{$location.country}}
"8507 Hudson Alley, Rochester, Wisconsin, 96512, United States"
Mock locales
Customize the Entire Mock Response (Mock Expectations)
Setting a Mock Expectation
Background
Returning Fixed Data
1.
2.
3.
4.
Returning Conditional Data
Note Body parameters support only JSON, not XML. Parameter conditions cannot use {{variables}}
.If you use body parameters for expectation matching, the request body format must match the API spec (e.g., form-data, JSON, etc.). You can also add IP address conditions to restrict responses to specific IPs.
Returning Dynamic Mock Data
Example
{
"data": [
{% for i in range(0, 20) %}
{% if i>1 %},{% endif %}
{
"id": {{i}},
"firstname": "{{$person.firstName}}",
"lastname": "{{$person.lastName}}"
}
{% endfor %}
],
"success": true
}
"success": true
{{$...}}
syntax invokes Faker.js to generate random values.{% for ... %}
) and logic.{{i}}
refers to a Nunjucks loop variable—not an Apidog variable.Notes Apidog uses {{$...}}
for Faker.js expressions (not the native JS call syntax).Faker.js (native): faker.person.firstName()
Apidog: {{$person.firstName}}
Apidog project/environment variables (like {{variable}}
) are not available in mock expectations.
More Features
You can add custom headers to a mock expectation, useful for simulating authentication, pagination, or any other API contract.
In the "More" tab inside mock expectations, you can set:
Toggle each expectation on/off separately for local and cloud mock environments from the expectation list.