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.
⚡ A note on performances
Parsing the templating helpers inside big files can be a very intensive task (CPU and memory intensive). All the files in different formats than the one mentioned above will be streamed to improve performances.
If you need to send big files in one of the above formats but don't need to parse the templating, you can disable it in the route response settings. It will stream the file instead of parsing it and improve the performance.
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.