sermock
server mock for develop
Last updated a year ago by yleo77 .
MIT · Original npm · Tarball · package.json
$ cnpm install sermock 
SYNC missed versions from official npm registry.

sermock

Another Server Mock for web develop using Node.js

Why this one?

Simple

Usage

const mocker = require('sermock');

var config = {
  PORT: 3002,                     // PORT config, 3002 if you don't set
  nocache: false,                 // cache config
  static: ['./static'],           // static file dir
  apis: {
    '/bang': {                    // path
      'GET': {                    // Method and Response
        code: 0,
        msg: 'success'
      },
      'POST': '__REQ_QUERY__'     // Response the Querystring as JSON
    },
  },
  db_file: './sermock.1db.json',  // DB File Config
};

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

Current Tags

  • 0.2.0                                ...           latest (a year ago)

3 Versions

  • 0.2.0                                ...           a year ago
  • 0.1.1                                ...           2 years ago
  • 0.1.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 2
Dependencies (6)
Dev Dependencies (3)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |