puer-mock

NPM version changelog license

Puer + Mock.js = A configurable mock server with configurable mock(random) data.

Start a mock server never ever so easy and configurable, no code needed, you only need config some mock api route and some mock data template, it all done!

features

install

Please install puer first.

Puer - more than a live-reload server , built for efficient frontend development

npm install puer -g

And then install puer-mock package in your project root directory.

cd yourprojectdir
npm install puer-mock

If your project has a package.json file, suggest save puer-mock to devDependencies.

cd yourprojectrootdir
npm install puer-mock --save-dev

usage

  1. copy node_modules/puer-mock/example files to your project root directory
  2. cd yourprojectrootdir
  3. puer -a _mockserver.js

    You may define a npm script in package.json, then use npm run dev next time.

    "dev": "puer -a _mockserver.js"
  4. view mock api

    • open http://localhost:8000/api/configdemo-response/mock view mock api return mock data
    • open http://localhost:8000/api/configdemo-response/mock?callback=test view mock api return mock data by JSONP
    • open http://localhost:8000/_apidoc.html view built-in all mock api doc
  5. define your mock api in _mockserver.json
  6. view your mock api(Yes! it with immediate effect)

config

The minimal _mockserver.json

{
    "api": {
        "GET /api/users": {
            "response": {}
        }
    }
}

Please view mockserver config doc for more detail info.

You can see more settings to config mock server in _mockserver.json.

customize

example

眼见为实耳听为虚, puer-mock 让你一秒钟就能拥有一个强大的 mock server, 所以请不要再自己手工做假数据了, 赶快尝试一下让你的工作效率翻番吧!

配置 API 并生成随机数据

puer-mock-example

查看所有的 API 接口文档

通过 /_apidoc.html 查看接口文档

puer-mock-api-doc-html

通过 /_apidoc 直接查看 JSON 数据, 即查看 mock server 配置了哪些 API(使用 FeHelper 插件 格式化了 JSON 数据)

puer-mock-api-doc

one more thing

谁需要这个工具

感谢 puer 提供了如此强大的 mock 机制, 感谢 Mock.js 带来的假数据, 我才有幸做了这么一个扩展工具.