-
Install
npm i -D @mocks-server/main
-
Add script
"scripts": {
"mocks": "mocks-server",
},
-
Run (if this command have not create
mocks.config.js
=> manual create one)npm run mocks
-
Folder structure
project-root/
├── mocks/
│ ├── documents/ <- place your openapi.json
│ │ └── openapi.json
│ ├── openapi/ <- openapi definitions
│ │ └── definitions.js
│ ├── routes/ <- DEFINE YOUR ROUTES HERE
│ │ ├── common.js
│ │ └── users.js
│ └── collections.js <- DEFINE YOUR COLLECTIONS HERE
└── mocks.config.js <- DEFINE YOUR CONFIGURATION HERE
- Main concepts
- Routes: A
route
defines the url and method of an API resource. Wildcards can be used in urls and methods, so oneroute
can simulate one real API resource, or many. - Variants: Each
route
can contain many differentvariants
. Eachvariant
can define a response to send, or a middleware to execute, or a url to proxy the request, etc. - Collections: A
collection
of route variants defines all current routes and variants in the API mock. They can be created extending other collections. So, you can store many collections and change the whole API behavior by simply changing the current one.