Mocks server is very flexible and permissive with the files structure inside the
mocks folder. It will load any fixture or behavior defined in any
.json file at any folder level.
You can have your fixtures and behaviors definitions separated and organized in as many files and folders as you want.
You can define your fixtures or behaviors in json format, defining one per file, or in an array containing multiple of them, or even all of them (fixtures and behaviors can also be defined in the same file)
You can use an object to export your definitions. The Mock Server will search at the first level of exported objects and will load any fixture or behavior defined in it.
The server accepts exports as arrays, and will load any fixture or behavior defined in it.
You can also define one behavior or fixture per file, and export it directly:
As a good practice, for a better maintainability, we recommend to use
behaviors.json file in the root of the
To organize fixtures, a good approach can be to create a folder for each api "domain", containing a different
json file with all fixtures of a same entity:
We strongly encourage to assign very descriptive ids to the "fixtures" and "behaviors", as they will be used afterwards in the CLI, the Api, and all other possible Mocks Server interaction methods.
A good pattern for assigning an id to a fixture can be
[method]-[entity]-[short-description], as in
For assigning id to behaviors, we recommend to maintain a base behavior named as
default. The rest of behaviors should extend from it (at least indirectly), and their ids should be a short description of the behavior itself, for example: