Mock expectations
Mock
tab in endpoints to add mock expectations.Returning fixed data
Click "New expectation".
Add an expectation name, leave the conditions blank.
Fill in the response you want to return in the Response data and save.
Copy the mock URL to access this endpoint.
Returning conditional data
{{variables}}
.Returning dynamic mock data
{
"data": [
{% for i in range(0, 20) %}
{% if i>1 %},{% endif %}
{
"id": {{i}},
"firstname": "{{$person.firstName}}",
"lastname": "{{$person.lastName}}"
}
{% endfor %}
],
"success": true
}
{{$ ... }}
syntax is used by Faker.js to generate random realistic data. However, unlike the native syntax, Apidog transforms it into the {{$ ... }}
reference format. The comparison with the native syntax is as follows:faker.person.firstName()
{{$person.firstName}}
{% for ... %}
syntax is from Nunjucks, allowing you to create loops and generate multiple items.{{i}}
in the example is not an Apidog variable, but a Nunjucks variable. Apidog variables cannot be used in mock expectations.More features
Modified atΒ 2025-03-14 08:42:26