# mocking

> mocking, mock api requests for frontend & native developers, have local & remote mode.

Latest version **1.0.8** (published 2014-12-08) · ISC license · 0 weekly downloads

## Install

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

Provides the command `mocking`.

## 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.0.8 |
| Published | 2014-12-08 |
| First published | 2014-12-06 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 6 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | peichao |
| Maintainers | chao2 |
| Keywords | mock, imock, api, mock server, mock api, mocking, http, test, development |

## Links

- npm: https://www.npmjs.com/package/mocking
- Repository: https://github.com/peichao01/mocking
- Issues: https://github.com/peichao01/mocking/issues
- npm.io page: https://npm.io/package/mocking

## Dependencies (6)

- [async](https://npm.io/package/async.md) ^0.9.0
- [express](https://npm.io/package/express.md) ^4.10.2
- [fs-extra](https://npm.io/package/fs-extra.md) ^0.12.0
- [underscore](https://npm.io/package/underscore.md) ^1.7.0
- [body-parser](https://npm.io/package/body-parser.md) ^1.9.2
- [cookie-parser](https://npm.io/package/cookie-parser.md) ^1.3.3

## Alternatives

- [duck](https://npm.io/package/duck.md) — 4.2M weekly downloads
- [ava](https://npm.io/package/ava.md) — 560.2K weekly downloads
- [storybook-addon-module-mock](https://npm.io/package/storybook-addon-module-mock.md) — 71.7K weekly downloads
- [@ethereum-waffle/mock-contract](https://npm.io/package/@ethereum-waffle/mock-contract.md) — 40.0K weekly downloads
- [aws-elasticsearch-connector](https://npm.io/package/aws-elasticsearch-connector.md) — 37.4K weekly downloads

## Recent versions

- 1.0.8 (latest) — 2014-12-08
- 1.0.7 — 2014-12-08
- 1.0.6 — 2014-12-08
- 1.0.5 — 2014-12-06
- 1.0.4 — 2014-12-06
- 1.0.2 — 2014-12-06
- 1.0.1 — 2014-12-06
- 1.0.0 — 2014-12-06

## README

mocking
=====

mock the api server, make the development of frontend & native(IOS/androind) disengaged from the server side development dependence. api server may be not stable in the developement period and the api can not be requested.

数据接口模拟，使【web前端/客户端】开发完全摆脱对【服务端】的依赖。避免因为接口不稳定对前端开发的影响。


mocking has `local` and `remote` mode, means the api can be responsed by the local javascript file or the online server, just switch each route controll in the config file(mocking.json) individually.    

mocking有两种模式：`local` 和 `remote`，意味着访问 api 时可以使用本地javascript文件或者线上服务器来响应请求，只需要在配置文件(mocking.json)中单独的针对每一个路由来切换即可。


download and run it, you will know all details. so easy!  

下载并运行一下，你就知道所有的一切了，so easy!

Install
----------
```shell
$ npm install mocking --save-dev
```

Config
----------
edit `mocking.json` or add and edit `mocking.custom.json`. see the example `mocking.json` file for more infomation.

Running
-------------
```shell
$ npm start
```

Usage
-----

set `port` at package.json->mocking->port


mocking.json

```javascript
{
    // use the custom config overwrite the defaults, and add the file in the `.gitignore` file, this is useful in the team.
    // 可以使用自定义配置覆盖默认配置，并把这个文件添加到 `.gitignore` 中，在团队协作时使用
    "customConfigFile":"./mocking.custom.json",
    // the online server host, this will be used in the remote mode.
    // 线上服务器的地址，在使用 `remote` 模式时会用到
    "api_remote_origin":"http://test.baidu.com",
    "api":[
        // 每一个单独的路由; single route
        {
            // this route will be ignored if `type === 'comment'`
            "type":"xx",
            // *important* 
            "rule":"/api/local/{order_id}",
            // if use the local file to response，是否使用本地模式
            "useLocal":true,
            // 如果使用remote模式，则，需要访问的线上地址，如果不是以 http 开头，则需要配置 `api_remote_origin`
            "remoteUrl":"/api/remote",
            // 如果使用local模式，则，需要使用的本地文件
            "localPath":"./data/test_local.js",
            // all other properties are as comments.其他一切字段都是用来备注的
            "":""
        },
        {
         // ...
        }
    ]
}
```

data/test_local.js

```javascript
// request path: /api/local/3
module.exports = function(req, res){
  var method = req.method
  var id = req.params.order_id
  var response
  if(method == 'GET'){
    response = {
      id: id
    }
  }
  else{
    response = {
    }
  }
  return JSON.stringify(response)
}
```

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