restmock

0.2.3 • Public • Published

restmock

Mock REST response on Server or Browser.

Server Mock

It can create a quick REST server by specifying routes in a json configuration file, additionally supporting static path.

restmock [configure file] : default mock.json

Browser Mock

It replaces window.XMLHttpRequest, and load mock.json in target project as configuration.

  • only support browserify bundling
  • steps
    • $ npm install restmock
    • write mock.json in root of target project
    • add require('restmock') to project main file
    • you have to remove require('restmock') in production environment.

Configuration

It supports all express method, with more specifically following route type

  • get
  • post
  • patch
  • put
  • delete
  • static : create a static folder with response as target folder

Example

{
    "port":9080,
    "routes":[
        {
            "path":"/test",
            "type":"get",
            "response":{
                "_id":"13",
                "name":"jack",
                "foo":"bar"
            }
        },
        {
            "path":"/a",
            "type":"post",
            "response":{
                "_id":"23",
                "name":"jack"
            }
        },
        {
            "path":"/static",
            "type":"static",
            "response":"www"
        }
    ]
}

/restmock/

    Package Sidebar

    Install

    npm i restmock

    Weekly Downloads

    10

    Version

    0.2.3

    License

    none

    Last publish

    Collaborators

    • lalalic