1.0.9 • Published 10 years ago

byg v1.0.9

Weekly downloads
-
License
MIT
Repository
-
Last release
10 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

10 years ago

1.0.8

10 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago