Skip to content

grace-mock 扩展了mockjs接口,提供简便方式使得在开发阶段真实模拟接口请求与响应。

Notifications You must be signed in to change notification settings

leolin1229/grace-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grace-mock

grace-mock 扩展了mockjs接口,提供简便方式使得在开发阶段真实模拟接口请求与响应。

npm version

特性

  • 完整支持mockjs所有接口,具备mockjs所有特性
  • 使用后台开发思维模拟真实接口请求与响应

安装

npm install grace-mock -D

用法

mockjs接口请移步这里.

CommonJS

var GraceMock = require('grace-mock');

var api = {
  'GET /your/api': function(req, res) {
    var _req$query = req.query,
        pageIndex = _req$query.pageIndex,
        pageSize = _req$query.pageSize;

    var mockData = GraceMock.mock({
      code: 200,
      success: true,
      data: {
        pageIndex: +pageIndex || 1,
        pageSize: +pageSize || 50,
        total: 100,
        totalPage: Math.ceil(100 / pageSize),
        'rows|100': [{
          'id|+1': 1,
          title: '@title',
          createTime: '@datetime',
        }],
      },
    });

    res.json(mockData);
  },
};

GraceMock.$wrapper(api);

ES6

import GraceMock from 'grace-mock';

const api = {
  'GET /your/api'(req, res) {
    const { pageIndex, pageSize } = req.query;

    const mockData = GraceMock.mock({
      code: 200,
      success: true,
      data: {
        pageIndex: +pageIndex || 1,
        pageSize: +pageSize || 50,
        total: 100,
        totalPage: Math.ceil(100 / pageSize),
        'rows|100': [{
          'id|+1': 1,
          title: '@title',
          createTime: '@datetime',
        }],
      },
    });

    res.json(mockData);
  },
};

GraceMock.$wrapper(api);

License

MIT.

About

grace-mock 扩展了mockjs接口,提供简便方式使得在开发阶段真实模拟接口请求与响应。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published