Easy Mock 是一个可视化,并且能快速生成模拟数据的持久化服务。简单来说,easy-mock可以提供api接口,让程序员在写好程序以后进行数据模拟。
使用easy-mock
第一步
创建一个项目
第二步
填写信息,这里项目名和url都是按照自己的意愿来填写,这会为最后生成的api数据接口提供地址
第三步
创建mock
第四步
最后就可以在这里写下mock的代码啦!
大家可以参考一下,mock.js代码编写的规则:
{
"base": {
"range": "@range(3, 7)",
"string": "@string(7, 20)",
"character": "@character('abcde')",
"float": "@float(60, 100)",
"integer": "@integer(60, 100)",
"natural": "@natural(60, 100)",
"boolean": "@boolean"
},
"date": {
"date": "@date",
"time": "@time",
"datetime": "@datetime",
"now": "@now"
},
"image": {
"image": "@image('200x100', '#50B347', '#FFF', 'EasyMock')"
},
"color": {
"color": "@color",
"hex": "@hex",
"rgb": "@rgb",
"rgba": "@rgba",
"hsl": "@hsl"
},
"text": {
"paragraph": "@paragraph(1, 3)",
"sentence": "@sentence(3, 5)",
"word": "@word(3, 5)",
"title": "@title(3, 5)",
"cparagraph": "@cparagraph(1, 3)",
"csentence": "@csentence(3, 5)",
"cword": "@cword('零一二三四五六七八九十', 5, 7)",
"ctitle": "@ctitle(3, 5)"
},
"name": {
"first": "@first",
"last": "@last",
"name": "@name",
"cfirst": "@cfirst",
"clast": "@clast",
"cname": "@cname"
},
"web": {
"url": "@url",
"domain": "@domain",
"protocol": "@protocol",
"tld": "@tld",
"email": "@email",
"ip": "@ip"
},
"address": {
"region": "@region",
"province": "@province",
"city": "@city(true)",
"county": "@county(true)",
"zip": "@zip"
},
"helper": {
"capitalize": "@capitalize('hello')",
"upper": "@upper('hello')",
"lower": "@lower('HELLO')",
"pick": "@pick(['a', 'e', 'i', 'o', 'u'])",
"shuffle": "@shuffle(['a', 'e', 'i', 'o', 'u'])"
},
"miscellaneous": {
"id": "@id",
"guid": "@guid",
"increment": "@increment(1000)"
}
}
小编在这里就知识创建了一个get方法,方便用postman调用!