1.3.1 • Published 9 years ago
easy-mocker v1.3.1
EASY MOCKER
This is a NodeJs webserver intended for development. It provides a basic and quick way to define mock response trough a collection of JSON responses and a JSON file containing endpoint definition.
Installation
Grab it form npm: npm install easy-mocker
Minimum usage: easy-mocker -c config.json -d folder/
Configuration
| Option | Value | Description |
|---|---|---|
-c* | path/to/config.json | Path to api definition |
-d* | path/to/mock-directory | Path to mock folder |
-p | port | Webserver port |
-u | null | Return different models for different user |
Options marked with * are mandatory.mv m
Configuration file
This is a sample structure for a configuration file:
{
"auth": {
"headerField": "x-randomField" //optional (default to `x-userid`)
},
"endpoints": [
{
"url": "users",
"base": "api/",
"methods": ["GET"],
"param": "id"
},
{
"url": "posts",
"base": "api/",
"methods": ["GET", "POST"],
"param": "id"
}
]
}That will generate the following endpoints:
GET /api/usersGET /api/users/:idGET /api/postsGET /api/posts/:idPOST /api/postsPOST /api/posts/:id
MOCK Files
You can provide data to be loaded as a starting point for your development server. They should be located in the Mock Folder directory (-d option).
Examples for this files can be found in spec/mocks, anyway they are plain JSON arrays of objects.
