Template Mock - Overview¶
If you need mock responses that are not static (for example, containing random data or data retrieved from the request), but you don't want to write Javascript code, you may use a template mock. This type uses Handlebars notation and provides a group of helpers that address an extensive set of use cases.
You may use templates to render the response body as well as response headers.
This section describes how to access request fields and state, lists available helpers, and gives some examples of template mocks.
Runtime Versions¶
- Version 1.0 (deprecated) - see Template Mock Runtime - Version 1.0
- Version 2.0 (current) - see Template Mock Runtime - Version 2.0
Error Handling¶
There are several problems you may encounter during the writing of the template body:
- You may access non-existent fields for the request (for example, due to a typo:
req.bod
instead ofreq.body
). In this case, the empty string value is used and a log entry is listed in the Request Logs. - You may use not existing helpers or pass invalid parameters to a helper. In this case, the empty string value is used, and a log entry is listed in the Request Logs.
- You may incorrectly use Handlebars expressions (for example, forget about opening "{{" or closing "}}" tokens). In this case, HTTP code 500 is returned as a response and a log entry is listed in the Request Logs.
Last update: September 2, 2020