Open
Description
名称: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": "张三"
}
Metadata
Metadata
Assignees
Labels
No labels