Besides using the body editor, Mockoon allows you to serve different files for each route. File serving should be the preferred method when you want to send lots of data.
To serve a file, you must provide a path in the file input field:
When a file path is provided, the body editor content will be ignored.
You can either provide an absolute path like
/home/username/file.json or a relative path. Starting with v1.16.0, relative paths are resolved from the environment's file location. You can check the environment's file location by right-clicking on an environment en select "Show in folder" in the contextual menu:
Prior to v1.16.0, relative file paths were resolved from the application executable. This is also supported by the CLI since its version 1.2.0.
Templating is available in both the file content and the file input field.
As for the body editor, templating will be parsed inside files for a limited set of MIME types (
application/xml). You can use all the available templating helpers to generate dynamic mock data.
Templating can be disabled both for the body editor and the file content. Please refer to the templating documentation for more information.
Templating is also supported directly in the file input field. It allows to dynamically generate the file path using helpers. Please refer to the templating documentation for more information.
By default, Mockoon will return an error in the body when a file is not found. It will still keep the status code you set up on your route response. You can instead choose to automatically return a 404 by activating an option in the route response settings:
This option will also fall back to use the content present in the body editor.