1.0.0 • Published 5 years ago

mockojs v1.0.0

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

Mocko

Service for API mock

Install

npm install -g moko

Usage

moko [command] [options]

Serve

moko serve -c moko.json -p 3001

port

  • You can specify the server listening port by -p, --port.
  • Moko will use 3001 as default port.

config

  • Moko only support json formated configuration for api mock.
  • You can specify config file by -c, --config.
  • It will use moko.json in current working directory as default.

Basic Example

Moko configuration is like below:

{"path": { "method": response}}

There are three types of response: 1. object

{
    "get": {
            "result": [
                {
                    "name": "wave",
                    "alias": "lts"
                },
                {
                    "name": "radar",
                    "alias": "pas"
                }
            ],
            "count": 2
        }
}
  1. string
{
    "post": "OK"
}
  1. reference
{
    "get": "ref#monitors.json"
}

Full Example:

// moko.json
{
    "/projects": {
        "get": {
            "result": [
                {
                    "name": "wave",
                    "alias": "lts"
                },
                {
                    "name": "radar",
                    "alias": "pas"
                }
            ],
            "count": 2
        },
        "post": "OK"
    },
    "/project/wave/monitors": {
        "get": "ref#monitors.json"
    }
}

Moko will handle the below routes:

GET /projects
POST /projects
GET /project/wave/monitors