Neanderthal Pudding Mix

    egg-api-mock

    1.0.2 • Public • Published

    egg-api-mock

    NPM version build status

    An egg plugin for api mock, enabled under local development default.

    Install

    $ npm i egg-api-mock --save

    Usage

    Add egg-api-mock as plugin

    // {app_root}/config/plugin.js
    exports.apiMock = {
      enable: true,
      package: 'egg-api-mock',
    };

    Configuration

    // {app_root}/config/config.default.js
    exports.apiMock = {
      dir: 'mock', // default mock dir
      env: [ 'local' ], // enabled under local development default
      glob: '**/*.mock.js', // default glob
    };

    You can use koa-router like methods in ${dir}/*.mock.js

    Example:

    1.mock.js

    module.exports = {
      "/api/user/:id": (ctx) => {
        ctx.body = ctx.params.id;
      },
      "/api/users": {
        success: true
      },
    };

    2.mock.js

    module.exports = {
      "POST /api/posttest": (ctx) => {
        ctx.body = ctx.request.body;
      },
    };

    Then you can request you app:

    /api/user/1 : 1
    /api/user/2 : 2
    /api/users : {success: true}
    /api/posttest : post data
    

    License

    MIT

    Install

    npm i egg-api-mock

    DownloadsWeekly Downloads

    64

    Version

    1.0.2

    License

    MIT

    Unpacked Size

    6.01 kB

    Total Files

    7

    Last publish

    Collaborators

    • zinkey