Travis CI - Status
NPM - Mock JSON API
A node module for generating dummy data quickly and mocking an API to deliver that data as json objects defined by the developer
- jsonStore: This is the local file location for the actual data that gets generated. The data will be stored in this json file and served up on request by node. This allows us to serve up well-known data vs. generating it everytime, thus simulating a database (of sorts).
- mockRoutes: An array of routes to mock
- name: The unique identifier of the service method to be mocked
- mockRoute: The URL of the route to mock - a regex
- testScope: The behavior of the route response; success, fail, or error
- errorBody: The text that will be displayed in the response of any error thrown
- method: POST, DELETE, GET, PUT, etc
- testScenario: Determines which JSON template to return in the array when testScope is "success" by either defining the index of the array or the name of the template
- latency: in milliseconds. Will delay the response by set number of miliseconds. Can be a single number like 3000, a string like '3000' or a range of numbers as a string like '2000-7000'. If a range, it will randomly select a number in that range on each request.
- jsonTemplate: The actual object to be returned from the mock route. This will also tell node how to construct the dummy data the first time the route is requested. It's simply an array of strings, functions or objects that return string representations of JSON objects laced with dummy JSON notation.
- data: Your own data to be used with dummy-json.
- helpers: Custom helpers to be used with dummy-json. Refer to the dummy-json documention for more information.
On The Fly Modification
- If you need to change scenario, scope or latency on the fly, just GET the route you want to modify and add the property you want to modify to the querystring with a new value.
- Currently you can modify testScenario, testScope, and latecy values.
- For example:
http://myserver.com/api/route?testScenario=foo will change the scenario of the /api/route route to foo from whatever is set in the mock object.
var express = ;
var mock = ;
server = ;
var mockapi =