Mock scripts
How it works
1.
2.
$$.mockResponse
object and/or $$.mockRequest
object.3.
4.
$$.mockResponse.setBody
method to rewrite the mockResponse with your modified data.5.
Using Mock Scripts
Switch to the Mock tab, where the Mock Script section is located at the bottom.
Turn on the script toggle.
Write your script and save it.
Script reference
Mock script example
1.
2.
page
value to match what was requested.total
value.3.
$$.mockRequest object
$$.mockRequest
object represents the incoming request in your mock script. It's similar to Postman's pm.request
object but with some additional features.1.
2.
Usage examples
$$.mockResponse object
$$.mockResponse
object represents the response that will be sent back. It's similar to Postman's pm.response
object but with additional methods for greater control over the mock response.1.
2.
3.
Usage examples
FAQ
A: Mock scripts cannot use variables. This is because variables are a feature of the Apidog client, but the mock engine is not part of the client, so it cannot reference variables in the client.
A: Mock scripts do not provide logging functionality. This is because the console is a feature of the Apidog client, but the mock engine is not part of the client, so it cannot output logs to the client.
A: Mock scripts are executed on the mock server, while pre and post scripts are executed on the Apidog client that sends the request. These are completely different environments, so the script syntax cannot be shared between them.
Modified atΒ 2025-03-14 08:24:46