Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[第 55 期] 开源项目自荐:mokia #395

Open
varHarrie opened this issue Mar 26, 2019 · 0 comments
Open

[第 55 期] 开源项目自荐:mokia #395

varHarrie opened this issue Mar 26, 2019 · 0 comments

Comments

@varHarrie
Copy link

名称:mokia
地址:https://github.com/varHarrie/mokia
描述:通过编写代码方式构建假模型,用于生成假数据,便于前端mock接口测试,假模型可以很方便在不同接口中复用。
特点:

  • 非常方便集成到现有项目
  • 支持TypeScript
  • 模型高度复用
  • 丰富的假数据生成器

使用方法:
1.安装npm install mokia --save-dev

import { decorators, mock, PORT, ServerConfig } from 'mokia'

class User {
  decorators.uuid()
  id: string

  decorators.fullName()
  name: string
}

const config: ServerConfig = {
  [PORT]: 3000,
  'GET /users': () => {
    return {
      users: mock.array(User, 0, 5)
    }
  },
  'GET /users/:id': () => {
    return mock(User)
  }
}

export default config

2.配置scripts

"scripts": {
  "mock": "mokia mock.ts",
}

3.运行

npm run mock

4.浏览器打开http://localhost:3000/users/5,返回json:

{
  "id": "4fvke82k",
  "name": "张三"
}
@ruanyf ruanyf changed the title 开源项目自荐:mokia [第 55 期] 开源项目自荐:mokia Mar 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant