Mock json api ? This is a great command line tool for building 'CORS' api, it will create a node server to provide api service by scanning api js/json files in your working directory.
- support cross domain request
- support js files that use CommonJS
- support json file, object or array
- support changing port, dynamic detecting
- support static files service
- support livereload when some api file is modyfied
- support open api in browser
Looks like this:
npm install -g mock-api-cli
or
yarn global add mock-api-cli (recommand)
cd your-work-directory
get help:
mock-api-cli -h (you can also use `mac -h`)
mock-api-cli -o (or mac -o)
you should create js/json files that defines the api request path, request method and response data, then we will serve those files via api
- path: the request path
- res: the response data, it is an object or an array
- type: request method, like 'get', 'post', 'put', 'delete', 'options'
dirname/user.js (use CommonJS)
module.exports = {
path: '/user',
res: {
code: Math.random() > .5 ? 200 : 400,
data: {
username: 'iceyangcc',
npm: 'https://www.npmjs.com/package/mock-api-cli'
}
}
}
you can custom you logic , you can export an array including many apis
list.json (also include "path", "res", "type"...)
[
{
path: '/detail/:id',
type: 'post',
res: {
}
},
{
path: '/login',
type: 'post',
res: {
}
}
]
The invalid object will be ignored
for more detail , visit https://github.com/iceyangcc/mock-api-cli
- koa / middleware
- shell
