I am a fairly simple mock server which serves JSON responses.
I am good at:
- simplicity
- install globally and use me in any directory where mocks exists
- can handle different scenarios for same API like error cases etc
- very descriptive logs in terminal
- daily evolving, tell me your problem I will try my best and try to resolve it
git clone https://github.com/naveen2593kumar/json-mock-server.git
cd json-mock-server
npm install
npm install -g
and here we go, Voilla!!!
git pull
npm install
npm install -g
I have few flags to pass the requirements you want, like
-p
OR --path
for path (this helps me to narrow down the search for JSON mocks)
-g
OR --glob
for json glob pattern (this is the pattern to find the JSON mocks)
-s
or --scenario
for scenarios (in JSON file you can set the responses for passed scenarios)
--port
for port
Below will serve all the JSON files under demo folder and try to serve response1
if exists otherswise response
at default port 8083
json-mock-server -p './demo' -g '*.json' -s 1
Below will serve all the JSON files under demo folder having naming pattern f*.json
at custom port 8084
json-mock-server -p './demo' -g 'f*.json' --port 8084
In order to use me at best, please follow the below format exactly, Few Samples
{
"method": "(get|post|put|delete|patch)",
"path": "/api/your/expected/endpoint",
"authorised": true, then I look for a authorisation header
"response": "expected response from the server"
"response<scenario>": "expected response from the server with specifc <scenario>"
}
- If global install does not work proply then you can always run me with my friend Mr.
node
node <directoryToJsonMockServer>/index.js -p './demo' -g 'f*.json' --port 8084