一:全局安装json-server

npm install json-server -g

二:在自己项目跟目录下存放mock/data.json,json内容如下:

 {
"roles": [
{
"id": 0,
"name": "SuperUser"
},
{
"id": 1,
"name": "User"
},
{
"id": 2,
"name": "Project Manager"
}
],
"users": [
{
"password": "wp123456",
"name": "王芃",
"avatar": "avatars:svg-1",
"email": "wpcfan@163.com",
"id": "37489e0c-df34-c261-71c4-ce75357e3035",
"projectIds": [
"Sk2HaTagb",
"Hya1moGb-"
],
"roleIds": [
0,
1,
2
]
},
{
"password": "Ls123456",
"name": "李四",
"avatar": "avatars:svg-2",
"email": "lisi@163.com",
"id": "BkkDvwee-",
"projectIds": [
"Sk2HaTagb"
],
"roleIds": [
1
]
}
],
"projects": [
{
"id": "Sk2HaTagb",
"name": "问题跟踪系统",
"desc": "用于 Bug 的内部跟踪和管理",
"coverImg": "/assets/img/covers/1.jpg",
"members": [
"37489e0c-df34-c261-71c4-ce75357e3035",
"BkkDvwee-"
]
},
{
"name": "某某公司 ERP 系统",
"desc": "为某某公司开发的定制化 ERP 系统",
"coverImg": "/assets/img/covers/20.jpg",
"members": [
"37489e0c-df34-c261-71c4-ce75357e3035"
],
"id": "Hya1moGb-",
"taskLists": [
"BylTyXiM-b",
"BkWpk7jGZb",
"H1fTyXjMWW"
]
},
{
"name": "新的项目二",
"desc": "大法师",
"coverImg": "/assets/img/covers/5.jpg",
"id": "O2kpMpP"
}
],
"taskLists": [
{
"name": "待办",
"projectId": "Sk2HaTagb",
"order": 1,
"id": "BkenST66lb"
},
{
"name": "已完成",
"projectId": "Sk2HaTagb",
"order": 3,
"id": "SkG3Ba6Tgb"
},
{
"name": "待办",
"projectId": "Hya1moGb-",
"order": 1,
"id": "BylTyXiM-b"
},
{
"name": "进行中",
"projectId": "Hya1moGb-",
"order": 2,
"id": "BkWpk7jGZb"
},
{
"name": "已完成",
"projectId": "Hya1moGb-",
"order": 3,
"id": "H1fTyXjMWW"
}
],
"tasks": [
{
"desc": "吃晚餐",
"taskListId": "BkenST66lb",
"ownerId": "37489e0c-df34-c261-71c4-ce75357e3035",
"completed": true,
"participantIds": [
"BkkDvwee-",
"37489e0c-df34-c261-71c4-ce75357e3035"
],
"dueDate": null,
"reminder": null,
"createDate": "2017-05-17T14:10:01.159Z",
"priority": 3,
"order": 1,
"remark": "",
"id": 1
},
{
"id": 2,
"desc": "赶快出发去万达",
"taskListId": "SkG3Ba6Tgb",
"ownerId": "37489e0c-df34-c261-71c4-ce75357e3035",
"completed": false,
"participantIds": [
"37489e0c-df34-c261-71c4-ce75357e3035"
],
"dueDate": "2017-06-12T16:00:00.000Z",
"reminder": "2017-07-18T16:00:00.000Z",
"createDate": "2017-05-19T10:03:58.794Z",
"priority": 2,
"order": 2,
"remark": "something"
},
{
"id": 3,
"desc": "什么情况啊",
"taskListId": "BkenST66lb",
"ownerId": "BkkDvwee-",
"completed": false,
"participantIds": [],
"dueDate": "2017-06-15T16:00:00.000Z",
"reminder": "2017-06-21T16:00:00.000Z",
"createDate": "2017-05-23T08:21:04.445Z",
"priority": 1,
"remark": ""
},
{
"taskListId": "BylTyXiM-b",
"desc": "登录鉴权过程中需携带 token 访问 API",
"completed": false,
"ownerId": "BkkDvwee-",
"participantIds": [],
"dueDate": "2017-07-03T16:00:00.000Z",
"priority": 2,
"remark": "",
"reminder": "2017-06-27T16:00:00.000Z",
"createDate": "2017-05-24T06:11:05.625Z",
"id": 4
},
{
"taskListId": "BkWpk7jGZb",
"desc": "增加统计报表功能",
"completed": false,
"ownerId": "37489e0c-df34-c261-71c4-ce75357e3035",
"participantIds": [],
"dueDate": "2017-07-25T16:00:00.000Z",
"priority": 1,
"remark": "",
"reminder": "2017-07-17T16:00:00.000Z",
"createDate": "2017-05-24T06:11:48.513Z",
"id": 5
},
{
"taskListId": "BylTyXiM-b",
"desc": "首页 banner 增加 2px 的 margin",
"completed": false,
"ownerId": "37489e0c-df34-c261-71c4-ce75357e3035",
"participantIds": [
"BkkDvwee-"
],
"dueDate": "2017-06-29T16:00:00.000Z",
"priority": 3,
"remark": "",
"reminder": null,
"createDate": "2017-05-24T06:12:59.718Z",
"id": 6
},
{
"taskListId": "BkWpk7jGZb",
"desc": "库存管理 -- 出库操作 API",
"completed": false,
"ownerId": "BkkDvwee-",
"participantIds": [
"37489e0c-df34-c261-71c4-ce75357e3035"
],
"dueDate": "2017-07-24T16:00:00.000Z",
"priority": 2,
"remark": "",
"reminder": "2017-07-17T16:00:00.000Z",
"createDate": "2017-05-24T06:14:47.575Z",
"id": 7
},
{
"taskListId": "H1fTyXjMWW",
"desc": "用户可以签入签出设备",
"completed": true,
"ownerId": "37489e0c-df34-c261-71c4-ce75357e3035",
"participantIds": [],
"dueDate": "2017-05-20T16:00:00.000Z",
"priority": 1,
"remark": "",
"reminder": "2017-05-20T16:00:00.000Z",
"createDate": "2017-05-24T06:16:24.575Z",
"id": 8
},
{
"taskListId": "BkWpk7jGZb",
"desc": "什么情况啊?",
"completed": false,
"ownerId": "37489e0c-df34-c261-71c4-ce75357e3035",
"participantIds": [],
"dueDate": null,
"priority": 3,
"remark": "",
"reminder": null,
"createDate": "2017-06-15T12:03:36.290Z",
"id": 9
}
],
"quotes": [
{
"id": "0",
"cn": "我突然就觉得自己像个华丽的木偶,演尽了所有的悲欢离合,可是背上总是有无数闪亮的银色丝线,操纵我哪怕一举手一投足。",
"en": "I suddenly feel myself like a doll,acting all kinds of joys and sorrows.There are lots of shining silvery thread on my back,controlling all my action.",
"pic": "/assets/img/quotes/0.jpg"
},
{
"id": "1",
"cn": "被击垮通常只是暂时的,但如果你放弃的话,就会使它成为永恒。(Marilyn vos Savant)",
"en": "Being defeated is often a temporary condition. Giving up is what makes it permanent.",
"pic": "/assets/img/quotes/1.jpg"
},
{
"id": "2",
"cn": "不要只因一次挫败,就放弃你原来决心想达到的梦想。(莎士比亚)",
"en": "Do not, for one repulse, forgo the purpose that you resolved to effect.",
"pic": "/assets/img/quotes/2.jpg"
},
{
"id": "3",
"cn": "想有发现就要实验,这项实验需要时间。—《神盾局特工》",
"en": "Discovery requires experimentation, and this experiment will take time.",
"pic": "/assets/img/quotes/3.jpg"
},
{
"id": "4",
"cn": "这世界并不会在意你的自尊,这世界希望你在自我感觉良好之前先要有所成就。",
"en": "The world won't care about your self-esteem. The world will expect you to accomplish something before you feel good about yourself.",
"pic": "/assets/img/quotes/4.jpg"
},
{
"id": "5",
"cn": "当你最终放开了过去,更好的事就会到来。",
"en": "When you finally let go of the past, something better comes along.",
"pic": "/assets/img/quotes/5.jpg"
},
{
"id": "6",
"cn": "我们学着放开过去伤害我们的人和事,学着只向前看。因为生活本来就是一往直前的。",
"en": "We learn to let go of things and people that hurt us in the past and just move on. For life is all about moving on.",
"pic": "/assets/img/quotes/6.jpg"
},
{
"id": "7",
"cn": "绝不要因为怕辛苦而拒绝一个想法、梦想或是目标,成功的路上难免伴随辛苦。(Bob Proctor)",
"en": "Never reject an idea, dream or goal because it will be hard work. Success rarely comes without it.",
"pic": "/assets/img/quotes/7.jpg"
},
{
"id": "8",
"cn": "我们在人生中会作出许多选择,带着这些选择继续生活,才是人生中最难的一课。《妙笔生花》",
"en": "We all make our choices in life. The hard thing to do is live with them.",
"pic": "/assets/img/quotes/8.jpg"
},
{
"id": "9",
"cn": "我总是对新的一天充满喜悦,这是一次新的尝试、一个新的开始,翘首以待,黎明之后或是惊喜。(约翰·博因顿·普里斯特利)",
"en": "I have always been delighted at the prospect of a new day, a fresh try, one more start, with perhaps a bit of magic waiting somewhere behind the morning.",
"pic": "/assets/img/quotes/9.jpg"
}
]
}

三:执行 “json-server mock/data.json” 显示如下效果

访问http://localhost:3000/此地址,就会访问到每个接口返回的数据

四:json-server支持GET,POST,PUT,PATCH,DELETE等REST命令

快速搭建REST API——json server的更多相关文章

  1. 玩转 SpringBoot 2 快速搭建 | RESTful Api 篇

    概述 RESTful 是一种架构风格,任何符合 RESTful 风格的架构,我们都可以称之为 RESTful 架构.我们常说的 RESTful Api 是符合 RESTful 原则和约束的 HTTP ...

  2. 拿nodejs快速搭建简单Oauth认证和restful API server攻略

    拿nodejs快速搭建简单Oauth认证和restful API server攻略:http://blog.csdn.net/zhaoweitco/article/details/21708955 最 ...

  3. json server的简单使用(附:使用nodejs快速搭建本地服务器)

    作为前端开发人员,经常需要模拟后台数据,我们称之为mock.通常的方式为自己搭建一个服务器,返回我们想要的数据.json server 作为工具,因为它足够简单,写少量数据,即可使用. 安装 首先需要 ...

  4. Python+Flask搭建mock api server

    Python+Flask搭建mock api server 前言: 近期由于工作需要,需要一个Mock Server调用接口直接返回API结果: 假如可以先通过接口文档的定义,自己模拟出服务器返回结果 ...

  5. 在Ubuntu上快速搭建基于Beego的RESTful API

    最近在研究Go,打算基于Go做点Web API,于是经过初步调研,打算用Beego这个框架,然后再结合其中提供的ORM以及Swagger的集成,可以快速搭建一个RESTful API的网站. 下面是具 ...

  6. Cucumber+Rest Assured快速搭建api自动化测试平台

    转载:http://www.jianshu.com/p/6249f9a9e9c4 什么是Cucumber?什么是BDD?这里不细讲,不懂的直接查看官方:https://cucumber.io/ 什么是 ...

  7. WAMP Server助你在Windows上快速搭建PHP集成环境

    WAMP Server助你在Windows上快速搭建PHP集成环境 原文地址 我想只要爬过几天网的同学都会知道PHP吧,异次元的新版本就是基于PHP的WordPress程序制造出来的,还有国内绝大部分 ...

  8. json:server 本地搭建

    做个记录, 第一步,我们新建一个文件夹. 第二步,打开文件夹,执行git,没有git可以下载一个.或者用命令行工具进入到这个文件夹! 第三步,初始化json  在git里执行npm init --ye ...

  9. 快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana)

    快速搭建应用服务日志收集系统(Filebeat + ElasticSearch + kibana) 概要说明 需求场景,系统环境是CentOS,多个应用部署在多台服务器上,平时查看应用日志及排查问题十 ...

随机推荐

  1. JQ遍历 input 并修改name属性

    1.执行完克隆行后,会出现name属相相同的问题 function addRow(){ var obj = $("tr[name='info']:last"); var objCl ...

  2. 【Henu ACM Round#17 A】Simple Game

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 肯定是放在m-1或者m+1的. (m-1是左边的点都离a最近,而m+1则是右边的点都离他最近. 看看哪个更好就行 [代码] #inc ...

  3. HDU 2883 kebab

    kebab Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HDU. Original ID: 2883 ...

  4. CF 246 div2 D Prefixes and Suffixes (全部前缀的出现次数)

    题目链接:http://codeforces.com/contest/432/problem/D 题意:对一个长度不超过10^5的字符串.按长度输出和后缀全然匹配的的前缀的长度,及该前缀在整个串中出现 ...

  5. android中9-patch图片的使用

    看了非常多文章的介绍,9.png图片有两种区域:可扩展区和内容显示区. 弄了半天才明确什么叫做可扩展区,什么叫做内容显示区. 分享一下自己的理解. 下图是某博客的截图: 图片来自:http://blo ...

  6. js---04 属性 this

    var oUl = document.getElementsByTagName('ul')[0]; var aLi = oUl.getElementsByTagName('li'); window.o ...

  7. 【转】BAT取当前日期的前一天

    ============================取前一天的日期       OK============================@echo off ::前一天的日期,格式化输出echo ...

  8. 用Vue+axios写一个实时搜索

    刚刚在学vue,试着写了一个实时搜索文件. 思路:1.input 通过v-model绑定.2.通过watch检测输入结果变化.3根据结果变化从api调用不同的数据. 代码如下: <!DOCTYP ...

  9. hostname---显示和设置系统的主机

    hostname命令用于显示和设置系统的主机名称.环境变量HOSTNAME也保存了当前的主机名.在使用hostname命令设置主机名后,系统并不会永久保存新的主机名,重新启动机器之后还是原来的主机名. ...

  10. Java中的继承和接口

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 这是个老话题,继承和接口是实现多态的两种方式,如果对象很多,其中一对一对的有共同点,建议用继承,如果 ...