sermock
Another Server Mock for web develop using Node.js
Why this one?
Simple
Usage
const mocker = require('sermock');
var config = {
PORT: 3002,
nocache: false,
static: ['./static'],
apis: {
'/bang': {
'GET': {
code: 0,
msg: 'success'
},
'POST': '__REQ_QUERY__'
},
},
db_file: './sermock.1db.json',
};
mocker.create(config);
mocker.start();
The db_file Config, just an example
{
"detail": {
"id": 1,
"title": "bala",
"content": "Lorem ipsum dolor sit amet."
},
"list": [{
"id": 1,
"title": "bala"
},{
"id": 2,
"title": "foo"
}]
}
Then you can request these api:
BTW, If you POST to http://localhost:3002/bang?id=1&msg=cool
and you will get these response (as same as querystring).
{id: 1, msg: 'cool'}
- Response with querystring when you set
_res=__REQ_QUERY__
as a querystring;
- Response the special status code when you set
_statusCode=XXX
, XXX is HTTP status code;
EOF