1.0.9 • Published 9 years ago

byg v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
9 years ago

byg

本地模拟请求测试

安装

$ npm install -g byg

例子

先在pathOptions.js配置

exports.paths = [
  '/api/orders',
  '/api/userInfo',
  '/api/list'
];

在 mock_test/source 创建对应的json文件

orders.json
userInfo.json
userInfo.json

json文件里的内容是mock数据模板(文档参考:http://mockjs.com)

运行 byg -m

在浏览器上访问:

  http://localhost:3000/api/orders
  http://localhost:3000/api/userInfo
  http://localhost:3000/api/list

或者

在 mock_test/ 创建index.html 里面用jQuery做异步请求

  $.ajax({
    url: 'http://localhost:3000/api/userInfo',
    dataType: 'json', // json | jsonp
    type: 'get',
    data: {'name': 'koa'},
    success: function(data){
      console.log(data);
    }
    // ,
    // headers: {
    //  'X-Requested-With': 'XMLHttpRequest'
    // }
  });

访问 http://localhost:3000

License

MIT

1.0.9

9 years ago

1.0.8

9 years ago

1.0.7

9 years ago

1.0.6

9 years ago

1.0.5

9 years ago

1.0.4

9 years ago

1.0.3

9 years ago

1.0.2

9 years ago

1.0.1

9 years ago

1.0.0

9 years ago