Mockizen is a minimal mock http server that can run anywhere and exposes predefined endpoints. Built with node webframework Express. Mockizen docker image is built on top of Node Alpine image and has 40 Mb image size when compressed.
Check out Sample Mock OAuth Server
Here's the docker command
docker run -p 9155:8080 -v {DIR_CONTAINS_SCENARIONS_JSON_AND_OTHER_MOCK_FILES}:/opt/app/mocks nazmialtun/mockizen:latest
Mockizen reads routes from scenarios.json file. First create scenarios.json file. Here is a sample :
{
"routes": {
"/live": {
"get": 200
},
"/api/v1/user": {
"get": "user-get.js",
"post": "user-post.js",
"delete": 202
},
"/userlist": {
"get": "users.json"
},
"/some-image.png": {
"get": "path/route-to-image.png"
},
"/v1/:production-id": {
"post": "production.js",
"/details": {
"get": "production-details.js"
}
}
}
}
For more details about routing please take a look at express routing guide
There are three ways to mock an endpoint:
- Declaring HTTP status code. (e.g "get" : 200) : Will return status code with empty or dummy body.
- Static file/content (e.g "get" : "image.png" ) : Will return static file
- Javascript file (e.g "post":"user.js" ) : Will execute javascript file. Javascript file should be in following format ;
module.exports = function (req, res) {
// Read request
// ....
// Set response
};
Third party npm packages are supported. Make sure packages.json that contains npm packages used by mock js file is placed in the same directory with scenarios.json.
Feel free to contribute by creating a pull request