Without using a UI - ploiu/mock-server GitHub Wiki
Sometimes you don't want to use a GUI, or maybe you see web browsers as unnecessary bloat. This page will tell you how to create routes without the use of the UI.
Config Location
By default, the config file is located at ./config.json
. This can be changed by passing the --config
flag when running the mock server and specifying a location.
Config Type Definition
Config File
{
configVersion: string, // automatically generated by the mock server, but set to 3.0 if you're manually creating this file
routes: ConfigRoute[]
}
ConfigRoute
{
title: string,
url: string,
method: 'GET' | 'PUT' | 'POST' | 'DELETE' | 'HEAD' | 'CONNECT' | 'OPTIONS' | 'TRACE' | 'PATCH',
responseHeaders: Record<string, string>,
response: string | null,
responseStatus: number,
isEnabled: boolean,
routeType: 'default' | 'pass-through',
redirectUrl?: string // only used if `routeType` is 'pass-through'
}
Example Config File
{
"configVersion": "3.0",
"routes": [
{
"title": "Example Route",
"url": "/HelloWorld/:name?:age",
"method": "GET",
"responseHeaders": {},
"response": "Hello, {{name}}! You are {{age}} years old",
"responseStatus": 200,
"isEnabled": true,
"routeType": "default"
},
{
"title": "passthrough test",
"url": "/passthrough",
"method": "GET",
"responseHeaders": {},
"response": null,
"responseStatus": 200,
"isEnabled": true,
"routeType": "pass-through",
"redirectUrl": "https://www.example.com"
}
]
}
Updating config during runtime
You can update the routes that the server listens for without having to restart the server. All you have to do is save your route file and make a POST
request to the server's /refreshConfig
route. By default, the url to hit this will be http://localhost:8000/refreshConfig
Route Log
The route log exists in the command line version, though it is slimmed down compared to the UI. While you can see if a request hit the server, you cannot see the headers or body. This is to prevent large request headers and bodies from completely filling up the console: