Skip to content

teone/easy-mocker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

44 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

EASY MOCKER

Build Status

NPM

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/users
  • GET /api/users/:id
  • GET /api/posts
  • GET /api/posts/:id
  • POST /api/posts
  • POST /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.