安装

前提:redis >=4.0、node>=8.9、mongo>=3.4

安装easyMock

  1. cd /usr/local
  2. sudo git clone https://github.com/easy-mock/easy-mock.git
  3. chmod 777 -R easy-mock
  4. cd easy-mock
  5. npm install
  6. npm run build
  7. pm2 start npm -- start

新建项目

1、访问项目: 访问7300端口,直接输入用户名和密码即可,会自动创建。

2、新建项目

image.png

3、新建接口

image.png

语法规范

列举一些常用的规则,详情可参考:
http://mockjs.com/examples.html
https://easy-mock.com/docs#shu-ju-zhan-wei-fu

  1. {
  2. "code": 200,
  3. "flag": true,
  4. "list|3": [{
  5. "id|+1": 1,
  6. "name": "@name",
  7. "cname": "@cname",
  8. "age|0-100": 1,
  9. "email": "@email",
  10. "ip": "@ip",
  11. "province": "@province",
  12. "city": "@city",
  13. "county": "@county",
  14. "countyAll": "@county(true)",
  15. 'url': "@url",
  16. 'enameLast': '@last',
  17. 'enameFist': '@first',
  18. 'cfirst': '@cfirst',
  19. 'clast': '@clast',
  20. 'point': '@integer',
  21. 'birthday': '@date',
  22. 'pic': '@image',
  23. 'title': '@title',
  24. 'content': '@cword(100)',
  25. 'url': "@url",
  26. 'area': '@region'
  27. }]
  28. }

结果:

  1. {
  2. "code": 200,
  3. "flag": true,
  4. "list": [
  5. {
  6. "id": 1,
  7. "name": "Susan Martinez",
  8. "cname": "邱洋",
  9. "age": 98,
  10. "email": "l.hnpx@xewvbnp.tp",
  11. "ip": "113.238.251.48",
  12. "province": "澳门特别行政区",
  13. "city": "铜仁市",
  14. "county": "九龙坡区",
  15. "countyAll": "九龙坡区",
  16. "url": "prospero://yfbtkvprq.cg/vce",
  17. "enameLast": "Harris",
  18. "enameFist": "Steven",
  19. "cfirst": "蒋",
  20. "clast": "桂英",
  21. "point": 6702989399816868,
  22. "birthday": "1978-08-21",
  23. "pic": "http://dummyimage.com/234x60",
  24. "title": "Ytyebwwsk Eitrblxi Egedkewix",
  25. "content": "接争点定管回原头办变则月认办事车酸出林层意等必改类带展广阶本适何该家王由看机最越权因第局最格状新同除空利两山识气查边七层方群半实格立些自生方之院算向区本响把见交想太队列年难南度上值们元什养最地达米社总",
  26. "area": "华东"
  27. },
  28. {
  29. "id": 2,
  30. "name": "Timothy Johnson",
  31. "cname": "顾磊",
  32. "age": 15,
  33. "email": "d.rucuzobr@ccjtfhhiow.uk",
  34. "ip": "83.89.96.20",
  35. "province": "江苏省",
  36. "city": "九龙",
  37. "county": "错那县",
  38. "countyAll": "错那县",
  39. "url": "telnet://lfnvm.it/lldockpa",
  40. "enameLast": "Anderson",
  41. "enameFist": "Paul",
  42. "cfirst": "钱",
  43. "clast": "杰",
  44. "point": -919069982655968,
  45. "birthday": "2017-09-18",
  46. "pic": "http://dummyimage.com/120x600",
  47. "title": "Pyzthtt Huxqvtrgi Bqkkno Wvigv",
  48. "content": "线分连心中议社华机完农价术厂红可文院八然观飞料十保应心称需料治志劳该将线速书持气由身原研它或做然色程积区道水需入做素除京我重区解林多开性人养压气土名取声更快低江型角走即复养非江示放查点们集内性次求铁种",
  49. "area": "东北"
  50. },
  51. {
  52. "id": 3,
  53. "name": "Anna Johnson",
  54. "cname": "贺强",
  55. "age": 75,
  56. "email": "e.qvuz@eqhwmi.nu",
  57. "ip": "218.189.210.155",
  58. "province": "陕西省",
  59. "city": "无锡市",
  60. "county": "同仁县",
  61. "countyAll": "同仁县",
  62. "url": "nntp://upstro.gp/vkhprdvsk",
  63. "enameLast": "Harris",
  64. "enameFist": "Mark",
  65. "cfirst": "廖",
  66. "clast": "桂英",
  67. "point": -7280164427756584,
  68. "birthday": "1999-09-30",
  69. "pic": "http://dummyimage.com/125x125",
  70. "title": "Rfdlthup Hcphcs Tqlsuvcig Gzcgf Eoceuhbv Uqjud",
  71. "content": "打革内局已及族法便设子你今常来度儿基权或实规别行效内结打特般公气接从党第广位边便委济几今切管保变劳为单非眼常增合价并片好时对务先法文十科准段构验况权据面算心事又等国立认国北识程酸清克群教或流手切收天立",
  72. "area": "华中"
  73. }
  74. ]
  75. }