To serve a json data file as a REST endpoint.
JSON REST Serve
A NodeJs tool to serve a JSON data as REST end points.
$ npm install json-rest-serve
- The JSON data should be an array of objects.
- Each object (data item) should be identifiable with a primary key property.
- The primary key should be either string or integer.
- The data item can have nested objects within it.
- The added resource should have atleast one data item in its data array.
- The tool uses the first data item to understand the structure of it. It then uses this information to enforce the same structure during the POST and PUT operations.
How to use
- Add one or more resources that you want to serve as REST endpoints.
- After adding, call the serve method with your preferred port number.
- name, key and data are required to add a resource.
let jsonRestServe = ;
Options and Parameters
||Forms the base of rest urls after http://localhost:9000
||This would be the name of the resource
||Name of the primary key attribute of the data item.
||This version value would be added to the url. Example: http://localhost:9000/v1/api/employee
||An array of objects with a definite primary key
||Used in get all operation which is paginated.
||The tool generates a schema when not provided
||You can provide a robust schema for your JSON data item. The schema should adhere to draft-04 of json-schema.org
||Port number of the REST endpoints
||Takes pre-defined formats provided by Morgan logging tool such as combined, common, dev, short, tiny, etc.
- Can serve any array of objects JSON data with any structure and with any primary key.
- Can add as many resources before calling serve method.
- Does not update the json file for PUT/POST/DELETE operations. All the changes you make through the REST calls will be lost once you terminate the process.
- CORS enabled
- Can be used as a developer tool and not for any production deployment.
- Filter, sort, search and field selection features are available with GET requests. See the generated apidocs (http:/documents/index.html) for more information.
- Primarily powered by Lodash and Restify
- Supported by other libraries such as Morgan, Ajv and Rimraf.
- Document site is powered by apidoc.