1.3.0 • Published 4 years ago

mouk-server v1.3.0

Weekly downloads
-
License
MIT
Repository
-
Last release
4 years ago

mouk server

a rest api mock server that help you start a rest-api-server in seconds

installation

npm install -g mouk-server

or with yarn

yarn global add mouk-server

configuration

mouk server will find api.js in current directory as configuration

api.js may looks like:

module.exports = {
  apis: [
    {
      url: "/user/info",
      method: "GET",
      wait: 3000,
      expr:{
        "gender|1": [0, 1],
        nickname: "@cname",
        username: "@word(6)"
      }
    },
  ]
}

Define your api route in apis array, one by one.

Route options:

optiontypedesc
urlstringapi entry
methodstringrest method, GET & POST supported currently
waitnumberapi response wait time (in millisecond)
exprobjectresponse body definition, see also mockjs doc
fnfunctiondata generate function, mockjs instance will passed as first argument, if fn is present, expr will be ignored

*ps: expr is more like a static way to define the shape of your response, if your requirement is way more complicate, you can consider using fn to return any kind of response data (even with logic)

use fn to generate response data

{
  url: "/data/with/fn",
  method: "GET",
  fn: (mockjs) => {
    const { cols } = mockjs.mock({ "cols|10": [{ "name": "@cword(1,3)", "props": "@word(3,5)" }] })
    const data = (new Array(10)).fill(-1).map(row => {
      const dataRow = {}
      cols.forEach(col => {
        dataRow[col.props] = mockjs.mock('@integer(0, 1000)')
      })
      return dataRow
    })
    return { name: mockjs.mock("@cword(3,5)") + "-表", cols, data }
  }
}

then this api will give anything returned by fn as response body

1.2.0

4 years ago

1.2.0-11

4 years ago

1.2.0-10

4 years ago

1.2.0-5

4 years ago

1.3.0

4 years ago

1.2.0-7

4 years ago

1.2.0-6

4 years ago

1.2.0-9

4 years ago

1.2.0-8

4 years ago

1.2.0-4

4 years ago

1.2.0-3

4 years ago

1.2.0-2

4 years ago

1.2.0-1

4 years ago

1.2.0-0

4 years ago

1.1.0

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago