This project is aimed to help UI developers create mock Express applications to allow for easier testing, and for setting up API calls to a server that may not exist yet. It is super easy to set up, and supports most use cases for hitting a REST API.
Install the package globally
npm install -g rest-mock-json
Use the below shape to build out your mock api. Example Here
rest-mock-json -f <path/to/your/json/filename.json>
You should be greeted with a few messages in the console, or errors pointing out what went wrong.
if you have npx, skip then installation step and run
npx rest-mock-json -f <path/to/your/json/filename.json>
This package can also be installed to your project and called from your package.json
npm install --save-dev rest-mock-json
{
"scripts": {
"mock-api": "rest-mock-json -f <path/to/your/json/filename.json>"
}
}
Optional values labelled.
{
"port": number, // Port the app will listen on
"baseUrl": string, // starts with "/"
"notFound": any, // OPTIONAL 404 response
"endpoints": [
{
"method": "GET", // GET | POST | PATCH | DELETE | PUT
"path": string, // starts with "/"
"shouldError": boolean, // OPTIONAL should respond with error response?
"response": {
"statusCode": number, // Status code for successful response
"body": any // JSON response for success
},
"error": {
"statusCode": number, // Status code for error response
"body": any // JSON response for error
}
}
]
}
- More dynamic responses
- Test coverage