rsm

rest-server-mock

A rest server configured with routes that return mock JSON responses

Showing:

Popularity

Downloads/wk

0

GitHub Stars

0

Maintenance

Last Commit

7yrs ago

Contributors

0

Package

Dependencies

2

License

MIT

Type Definitions

Tree-Shakeable

No?

Categories

Readme

RestServerMock

A Simple REST HTTP server that serves the configured JSON responses rest-server-mock

Currently it servers JSON responses with status code 200. Future versions will support more options including : status codes, headers, encodings, etc.

About

The motivation for implementing this module was to provide a quick and simple server to be used when developing a rest client. In that cases where the rest server has not been implemented yet, I wanted to have an HTTP server responding with some mock JSON responses, without relying on a more complex mocking framework.

Installation

npm install rest-server-mock

Configuration

The server's port and routes are configured in a JSON file:

Example file:

{

  "port": 3001

  , "routes": [

    {
      "path": "/a"
      , "type": "GET"
      , "response": {
        "field_1": "f1 get a ok"
        , "field_2": "f2 get a ok"
      }
    }

    , {
      "path": "/a"
      , "type": "POST"
      , "response": {
        "field_1": "f1 post a ok"
        , "field_2": "f2 post a ok"
      }
    }

    , {
      "path": "/a"
      , "type": "PUT"
      , "response": {
        "field_1": "f1 put a ok"
        , "field_2": "f2 put a ok"
      }
    }

    , {
      "path": "/a"
      , "type": "DELETE"
      , "response": {
        "field_1": "f1 delete a ok"
        , "field_2": "f2 delete a ok"
      }
    }

  ]

}

Usage

As a commandline tool

rest-server-mock path_to_configuration_file

As a module

// Include the module.
var restServerMock = require('rest-server-mock')
// Start the server. Returns a promise.
restServerMock('path_to_configuration_file/filename.json')
.then(function (server) {
    console.log('RestServerMock is listening on port: ', server.address().port, ' ...')
    console.log('Configuration file: ', process.argv[2])
}
, function (err) {
    console.log(err)
})
// Note that the restServerMock method returns a promise.

Running the tests

npm test

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100
No reviews found
Be the first to rate

Alternatives

No alternatives found

Tutorials

No tutorials found
Add a tutorial