Coder Social home page Coder Social logo

zeelq / puer-mock Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ufologist/puer-mock

0.0 2.0 0.0 141 KB

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

Home Page: http://ufologist.github.io/puer-mock/

License: MIT License

JavaScript 100.00%

puer-mock's Introduction

puer-mock

NPM version

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

  • effective immediately when config changed
  • JSONP support
  • CORS support
  • built-in API doc

install

Please install puer first.

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

npm install puer-mock

usage

  1. copy node_modules/puer-mock/example files to your project root directory
  2. cd your project root
  3. puer -a _mockserver.js
  4. view mock api
  • open http://localhost:8000/api/users view mock api return mock data
  • open http://localhost:8000/api/users?callback=test view mock api return mock data by JSONP
  • open http://localhost:8000/_apidoc view built-in all mock api doc
  1. define your mock api in _mockserver.json
  2. view your mock api(Yes! it with immediate effect)

config

The minimal _mockserver.json

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

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

  • comment is nice
  • config route and mock response data template is so easy
  • more data template please see Mock.js examples
  • disable a route is convenient
  • mock server will effective immediately when you changed _mockserver.json

customize

  • You may customize /_apidoc route service a more graceful doc.

    // _mockserver.js
    module.exports = require('puer-mock')(null, null, function(mockConfig) {
        // 任你自由发挥
        return '<pre>' + JSON.stringify(mockConfig, null, 4) + '</pre>';
    });
  • Play it fun with your imagination.

    // _mockserver.js
    var puerMock = require('puer-mock');
    var routeConfig = puerMock();
    // 其实你完全可以这样来玩, 在这里接着定义 route 即可, 发挥你的想象力
    // 例如定义一个常用的 500 接口, 来测试服务器报错的情况
    routeConfig['GET /500'] = function(request, response, next) {
        response.status(500).end();
    };
    module.exports = routeConfig;

example

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

配置 API 并生成随机数据

puer-mock-example

查看所有的 API 接口文档

puer-mock-api-doc

one more thing

谁需要这个工具

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

puer-mock's People

Contributors

ufologist avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.