Socket
Book a DemoInstallSign in
Socket

sermock

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sermock

server mock for develop

latest
npmnpm
Version
0.2.0
Version published
Maintainers
1
Created
Source

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:

  • http://localhost:3002/detail (GET and POST)
  • http://localhost:3002/list (GET and POST)
  • http://localhost:3002/list/1 (GET, PUT, DELETE, like Restful api)
  • http://localhost:3002/bang

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

FAQs

Package last updated on 05 Jun 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts