A lightweight, user-friendly, and powerful tool for mocking API endpoints. Useful for testing API client integrations, or performance testing your application without sending traffic to your API dependencies.
Runs in port 3000 by default.
docker run -d --name supermockapi -p 80:3000 dsumiskum/supermockapi
Configure a different port.
docker run -d --name supermockapi -p 80:5000 -e "PORT:5000" dsumiskum/supermockapi
Specify initial mocked api routes specification through volume mapping a folder with a routes.json
or the file itself to the container workdir (app is the workdir).
The application will look for a routes.json file in the workdir when booting up.
docker run -d --name supermockapi -p 3000:3000 -v "${pwd}/folder/routes.json:/app/routes.json" dsumiskum/supermockapi
Route specifications format (routes.json):
[
{
"path": "/product/:sku",
"method": "GET",
"status": 200,
"body": {
"message": "Server received your request for sku {sku}"
},
"responseDelay": 5000
},
{
"path": "/product/:sku",
"method": "POST",
"status": 500
}
]
supermockapi is meant to be lightweight, easy to deploy, and works for your Continous Integration needs. A big problem with performance testing services is isolating the external dependencies to get more predictable metrics, which would be useful if you are benchmarking your metrics overtime.
With supermockapi, you can deploy it with your application as a stack, with specified routes.json file. And/or you can use the super friendly UI to manually add mock api endpoints. The UI comes with a console log stream, so that you can monitor incoming requests all in one place.
You can do this via the UI or by configuring a routes.json file. Json file example where you take a parameter sku in the base path:
{
"path": "/product/:sku"
}
You can do this via the UI or by configuring a routes.json file. Json file example for returning a 200:
{
"path": "/product/:sku",
"status": 200
}
You can do this via the UI or by configuring a routes.json file. Json file example for returning a simple message:
{
"path": "/product/:sku",
"status": 200,
"body": {
"message": "Hello world!"
}
}
You can include values from the tokens bag in your response body. The syntax for this is {token}
.
{
"path": "/product/:sku",
"status": 200,
"body": {
"sku": "{sku}"
}
}
What is included in tokens:
- Any parameters in the base URL
- Any parameters in the querystring
- The request body
{body}
- The number of calls made to the base URL
{calls}
- A random number between 1 and 100
{random}
- The current timestamp
{timestamp}
You can do this via the UI or by configuring a routes.json file. Json file example for delaying response by 5 seconds:
{
"responseDelay": 5000
}
You can do this via the UI or by configuring a routes.json file. Json file example of a weighted response scenario using conditional behaviors:
{
"path": "/random",
"method": "GET",
"status": 200,
"conditionalBehaviors": [{
"condition": "{random} <= 30",
"status": 500,
"body": {
"message": "[Condition Triggered] Random = {random}"
}
},
{
"condition": "{random} <= 60",
"status": 404,
"body": {
"message": "[Condition Triggered] Random = {random}"
}
},
{
"condition": "{random} <= 90",
"status": 200,
"body": {
"message": "[Condition Triggered] Random = {random}"
}
},
{
"condition": "{random} <= 100",
"status": 206,
"body": {
"message": "[Condition Triggered] Random = {random}"
}
}
],
"body": {
"message": "Number of calls = {calls}"
}
}
Built using express js, the mock api endpoints have 3 priority levels:
- Routes hard coded in the application
- Routes you inject via routes.json
- Routes added dynamically via the API (/mockapi/route) that the UI uses
All routes are stored in memory. When you create routes.json file, make sure to include the required fields: path, method, and status.
If you want to contribute, the application is fairly standard node js app albeit it is using 7.0 features for async/await operators. So you will need:
- Node 7.10.0
- IDE like Visual Studio Code
- Docker engine