Easy Mock 是一個可視化酬核,并且能快速生成模擬數(shù)據(jù)的持久化服務(wù)鲸郊。簡單來說,easy-mock可以提供api接口溅蛉,讓程序員在寫好程序以后進行數(shù)據(jù)模擬公浪。
使用easy-mock
第一步
創(chuàng)建一個項目
第二步
填寫信息,這里項目名和url都是按照自己的意愿來填寫船侧,這會為最后生成的api數(shù)據(jù)接口提供地址
第三步
創(chuàng)建mock
第四步
最后就可以在這里寫下mock的代碼啦欠气!
大家可以參考一下,mock.js代碼編寫的規(guī)則:
{
"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)"
}
}
小編在這里就知識創(chuàng)建了一個get方法镜撩,方便用postman調(diào)用晃琳!