@crafts/mock-server
v0.0.12
Published
Zero config, simple mock server! Keep the mocks close within your code.
Readme
Mock Server
Zero config, simple mock server! Keep the mocks close within your code.
Features
- Simple way to create mock. Example.
- Pass
blob(mock files pattern) option for custom mock paths. - Proxy to actual server using
-por--proxy. All unmatched requested will be sent to proxy. - Out of the box watch method, if any new file is created/changed within the watch path, server will register them.
- Create mocks with dynamic URL for eg.
/org/:orgId/projects/ - Custom status code and delay.
- Disable specific mock using
disabledoption in mock.json.
Usage
Install it
npm i @crafts/mock-server
Add files
Add JSON files ending with .mock.json, anywhere in repo as show in example
Run the server
npx @crafts/mock-server
Set the base URL
Point at http://localhost:4000
Options available
| Option | description | default |
| ------ | ------------------------------ | --------------------------------------------- |
| blob | Pattern to match the mocks | /**/*.mock.json |
| proxy | Original/actual server address | -- |
| root | soruce dir for searching mocks | process.cwd() Path from where script is ran |
How to write mocks
Writing mocks is very easy, for real. Create a json file matching the search pattern (by default: /**/*.mock.json).
Example:
{
"mocks": [
{
"url": "/a",
"method": "PATCH",
"response": { "a": 2 },
"status": 201,
"delay": 500,
"disabled": false
}
]
}Options for mock
| Props | type | Required | | -------- | ------- | -------- | | url | string | true | | method | string | true | | response | object | true | | delay | number | false | | status | number | false | | disabled | boolean | false |
UI
Mock server comes with UI (beta) for better experiance.

Coming soon
Note: Mock server is in beta, things will break but should not fall apart.
Please follow the board for live updates
https://github.com/users/mukuljainx/projects/5
