imo

imock

restful mock server for front-developer

Showing:

Popularity

Downloads/wk

23

GitHub Stars

4

Maintenance

Last Commit

5yrs ago

Contributors

2

Package

Dependencies

9

Size (min+gzip)

597.2KB

License

ISC

Type Definitions

Tree-Shakeable

No?

Categories

Readme

imock

restful mock server for front-end developer

NPM

Build Status Coverage Status

Install

$ npm install imock -g

Usage

$ imock -j json -b api

Options

-j --json 可选,mock 文件目录,该目录下存放所有处理请求的 js

-b --base 可选,指定 mock 请求的 base path(若 base = api,则请求 mock 数据的地址为 http://localhost:{port}/api/{js-filename})

-p --port 可选,指定 mock server 端口号,默认 3000

-w --www 可选,指定静态服务器根目录(express.directory),默认当前目录

-t --target 可选,若 mock 目录没有相应处理请求的 js,则会使用 target 指定的服务器来处理

注:

1. www  base 可以是同层级或 www  base 的父目录,base 不能是 www 的父目录;
2. 通常 base  /mock  /api;
3. 前端 js 中请求地址为 http://localhost:3000/mock  http://localhost:3000/api

mock 请求处理文件 example

filename: shop-id.js

// request path: /mock/shop/1234
// request method: get
exports.get = function (req, res) {
    res.json(200, {
        code: 1,
        msg: {
            name: '小南国',
            shopId: 1234,
            level: 3
        }
    });
}

// request path: /mock/shop/1234
// request method: put
exports.put = function (req, res) {
    res.json(200, {
        code: 1,
        msg: '修改成功'
    });
}

filename: shop.js

// request path: /mock/shop
// request method: post
exports.post = function (req, res) {
    res.json(200, {
        code: 1,
        msg: '保存成功'
    });
}

Rate & Review

Great Documentation0
Easy to Use0
Performant0
Highly Customizable0
Bleeding Edge0
Responsive Maintainers0
Poor Documentation0
Hard to Use0
Slow0
Buggy0
Abandoned0
Unwelcoming Community0
100