Skip to content

The svrx plugin for mock.js , Zero config, Provide us with a convenient way to mock data

License

Notifications You must be signed in to change notification settings

svrxjs/svrx-plugin-mock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

svrx-plugin-mock

svrx npm

The svrx plugin for mock.js , Zero config, Provide us with a convenient way to mock data

Usage

Please make sure that you have installed svrx already.

Mock plugin must be used with routing dsl, it will register new action named mock

Via CLI

svrx -p mock --route route.js

Via API

const svrx = require('@svrx/svrx');

svrx({ plugins: ['mock'] }).start();

Then play it in your route.js

get('/blog/:id').to.mock({
  'code|+1': 202,
  'object|2': {
    '310000': 'ShangHai',
    '320000': 'JiangSu',
    '330000': 'ZheJiang',
    '340000': 'Anhui'
  }
});

get('/user/:id').to.mock('@paragraph');

Visit /blog/1 , and you will see output as below

{
    "number":202,
    "object":{
        "310000":"ShangHai",
        "330000":"ZheJiang"
    }
}

Thanks for routing dsl, mocking rule is also hot-reloading. If you update the rules, there is no need to restart the server-x.

see official mock.js reference for more details

Options

None.

License

MIT

About

The svrx plugin for mock.js , Zero config, Provide us with a convenient way to mock data

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published