api-fet
Version:
The mock-api-cl command line utility.
117 lines (79 loc) • 2.09 kB
Markdown
> 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:

```text
npm install -g mock-api-cli
or
yarn global add mock-api-cli (recommand)
```
```text
cd your-work-directory
get help:
mock-api-cli -h (you can also use `mac -h`)
```
>
```text
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)
```text
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"...)
```text
[
{
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
[](http://blog.nodejs.tech)
[](https://github.com/iceyangcc)
iceyangcc@sina.com