# mouk-server

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

Latest version **1.3.0** (published 2020-07-06) · MIT license · 0 weekly downloads

## Install

```sh
npm install mouk-server
pnpm add mouk-server
yarn add mouk-server
bun add mouk-server
```

Provides the command `mouk`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2020-07-06 |
| First published | 2020-05-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 8 |
| Unpacked size | 29.8 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | duanzm |
| Maintainers | dzmtoast |
| Keywords | mock, frontend, devtool |

## Links

- npm: https://www.npmjs.com/package/mouk-server
- npm.io page: https://npm.io/package/mouk-server

## Dependencies (8)

- [koa](https://npm.io/package/koa.md) ^2.12.0
- [chalk](https://npm.io/package/chalk.md) ^4.0.0
- [mockjs](https://npm.io/package/mockjs.md) ^1.1.0
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.14.0
- [inquirer](https://npm.io/package/inquirer.md) ^7.1.0
- [@koa/cors](https://npm.io/package/@koa/cors.md) ^3.1.0
- [commander](https://npm.io/package/commander.md) ^5.1.0
- [koa-router](https://npm.io/package/koa-router.md) ^8.0.8

## Alternatives

- [pagerjs](https://npm.io/package/pagerjs.md) — 60 weekly downloads
- [whistle.savefor-mock](https://npm.io/package/whistle.savefor-mock.md) — 4 weekly downloads
- [@scenarist/msw-adapter](https://npm.io/package/@scenarist/msw-adapter.md) — 0 weekly downloads
- [@dapih/visualkan](https://npm.io/package/@dapih/visualkan.md) — 0 weekly downloads
- [@ryze-digital/select-replace](https://npm.io/package/@ryze-digital/select-replace.md) — 0 weekly downloads

## Recent versions

- 1.3.0 (latest) — 2020-07-06
- 1.2.0-11 (next) — 2020-07-06
- 1.2.0 — 2020-07-06
- 1.2.0-10 — 2020-07-06
- 1.2.0-9 — 2020-07-06
- 1.2.0-8 — 2020-07-06
- 1.2.0-7 — 2020-07-06
- 1.2.0-6 — 2020-07-06
- 1.2.0-5 — 2020-07-06
- 1.2.0-4 — 2020-07-01
- 1.2.0-3 — 2020-07-01
- 1.2.0-2 — 2020-07-01
- 1.2.0-1 — 2020-07-01
- 1.2.0-0 — 2020-06-30
- 1.1.0 — 2020-05-20
- … 5 more at https://npm.io/package/mouk-server/versions

## README

# 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:

``` js
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:
|option|type|desc|
|---|---|---|
|`url`|string| api entry|
|`method`|string| rest method, `GET` & `POST` supported currently|
|`wait`|number| api response wait time (in millisecond)|
|`expr`|object| response body definition, see also [mockjs doc]|
|`fn`|function|data 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

``` js
{
  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

---
_Source: https://npm.io/package/mouk-server · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
