# mockbox

> An easy tool to mock restful http request

Latest version **0.1.1** (published 2017-05-31) · MIT license · 0 weekly downloads

## Install

```sh
npm install mockbox
pnpm add mockbox
yarn add mockbox
bun add mockbox
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2017-05-31 |
| First published | 2017-02-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 7 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | luke lee |
| Maintainers | lueklee |
| Keywords | mock, server, koa |

## Links

- npm: https://www.npmjs.com/package/mockbox
- Repository: https://github.com/lukesomnus/Mockbox
- Homepage: https://github.com/lukesomnus/Mockbox#readme
- Issues: https://github.com/lukesomnus/Mockbox/issues
- npm.io page: https://npm.io/package/mockbox

## Dependencies (7)

- [lodash](https://npm.io/package/lodash.md) ^4.17.4
- [koa-send](https://npm.io/package/koa-send.md) ^3.3.0
- [koa-views](https://npm.io/package/koa-views.md) ^5.2.0
- [koa-logger](https://npm.io/package/koa-logger.md) ^1.3.1
- [koa-static](https://npm.io/package/koa-static.md) ^2.0.0
- [koa-convert](https://npm.io/package/koa-convert.md) ^1.2.0
- [koa-bodyparser](https://npm.io/package/koa-bodyparser.md) ^2.3.0

## 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
- [@jig-ts/msw](https://npm.io/package/@jig-ts/msw.md) — 0 weekly downloads
- [rand-util-sdk](https://npm.io/package/rand-util-sdk.md) — 0 weekly downloads
- [@mspv-academy/carly-mcp-poc](https://npm.io/package/@mspv-academy/carly-mcp-poc.md) — 0 weekly downloads

## Recent versions

- 0.1.1 (latest) — 2017-05-31
- 0.1.0 — 2017-02-27

## README

# MockBox
基于koa开发的模拟数据请求服务器。

## 特点
- 可模拟GET，POST，PUT，DELETE请求
- 可定制返回数据
- 使用数据模板返回模拟数据
- 可校验请求参数

## 安装
``` 
git clone https://github.com/lukesomnus/Mockbox.git
npm install
npm run start
```

## 使用方法

### Hello
```
  const MockBox = require('./index.js');
  const mb = new MockBox();
  mb.hello();
  mb.run();  //default port 3000
```
访问http://localhost:3000/hello，将返回数据{msg:'hello'};
### 配置
```
 const mb = new MockBox({
     base:'/test',  // 请求基地址
     port:3000     //访问端口
 });

```
### 方法
#### MockBox.add()
添加模拟数据，数据格式如下
```
     const config ={
        url: '/test',  //请求地址
        method:'get',   //默认是get
        require:[],  //必需参数，eg:['id','name']
        returnData: {
            msg:'hello MockBox!'
        }  //返回的数据
    };
     mb.add(config);
     mb.run(3000);
```
### Mock.get()

模拟get请求
```
     const config ={
        url: '/test',  //请求地址
        require:[],  //必需参数，eg:['id','name']
        returnData: {
            msg:'hello MockBox!'
        }  //返回的数据
    };
     mb.get(config);
```
### Mock.post()

模拟post请求
```
     const config ={
        url: '/test',  //请求地址
        require:[],  //必需参数，eg:['id','name']
        returnData: {
            msg:'hello MockBox!'
        }  //返回的数据
    };
     mb.post(config);
```
### Mock.run(port)
启动mock服务器，port为端口号。

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