1.1.4 • Published 2 years ago

simple-rest-mock v1.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

simple-rest-mock

A simple mock server for RESTful APIs. Easily add new resources with CRUD support and simple data handling.

Usage

[PORT=] npx simple-rest-mock [--resources=] [--data=]

This will run a local server on the specified port with CRUD endpoints for given resources.

It will also create a local data.json file, which acts as a DB storage.

Options

NameDescriptionDefault
resourcesstring[] comma-separated list of stringsusers,posts
datastring path to the data file./data{timestamp}.json
portnumber port for the server3003

Examples

With no options


npx simple-rest-mock

The mock server will be running on port 3003, using data-<timestamp>.json to hold the data and serving the users and posts resources.

With all options


npx simple-rest-mock --resources=movies,genres --data=data.json --port=8080

The mock server will be running on port 8080, using data.json to hold the data and serving the movies and genres resources.

Resources

For each REST resource a set of CRUD endpoints are being created. For example, if you have specified movies as a resource at the time of starting the server, then the following endpoints will be served out-of-the-box:

MethodEndpointRequestResponseDescription
POST/moviesany JSON objectSame JSON object with new id propertyCreates a new movie with the provided data
GET/moviesN/AAn array of movie objectsFetches all movie records
GET/movies/:idN/AThe movie with the specified idFetches the movie record with the given id
PUT/movies/:idany JSON objectSame JSON object with specified idReplaces the movie record with the given id by the new object
DELETE/movies/:idN/AThe id of the removed recordRemoves the movie record by the given id

Data

All data is being stored in the data file, which you specify when starting the server. It's a simple JSON content, and you can manually change it to serve the data you want.

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.0

2 years ago