json server服务器
json文件可以理解为数据库
一、json-server快速搭建RESTAPI
安装:
sudo cnpm install -g json-server
启动(使用):
json-server指向json文件所在位置
data.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"
]
}
],
"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

API server启动在localhost:3000。支持GET,POST,PUT,PATCH,DELETE等REST命令。

每一个json数组对应一个表

资源以名词形式作为API路径。
二、测试REST API
浏览器测试get,但不能测试post,put, delete等。
几种常见的API测试工具
1、使用Postman测试常用API
下载:https://www.getpostman.com/
安装成功如下:

Get操作很简单,输入url,点Send即可。
Post操作需要在header中指明参数。
- 指明Content-Type是application.json

- Body中给出一个json对象

服务器返回刚才创建的对象。
json server强大的地方是,可以不传id,会自动生成。因为真实开放中也是在服务器生成ID的。

json文件中的数据也会被更新。
2、使用VSCode的REST Client插件

创建一个后缀名是.http的文件rest.http
REST Client用纯文本描述请求,POST Man是有图形界面的。
发出一个post请求到 http://localhost:8090/auth,它的Content-Type是什么类型,然后携带的json是什么。
注意:
- 在json和http头部上面有一个空行
- 需要用###将不同的请求隔离开
// Login
POST http://localhost:8090/auth
Content-Type: application/json;charset: utf-8 {
"username":"peng1",
"password":"peng1234"
} ###

本文作者starof,因知识本身在变化,作者也在不断学习成长,文章内容也不定时更新,为避免误导读者,方便追根溯源,请诸位转载注明出处:https://www.cnblogs.com/starof/p/9068983.html 有问题欢迎与我讨论,共同进步。
json server服务器的更多相关文章
- json server的简单使用(附:使用nodejs快速搭建本地服务器)
作为前端开发人员,经常需要模拟后台数据,我们称之为mock.通常的方式为自己搭建一个服务器,返回我们想要的数据.json server 作为工具,因为它足够简单,写少量数据,即可使用. 安装 首先需要 ...
- 接口神器之 Json Server 详细指南
简介 json-server 是一款小巧的接口模拟工具,一分钟内就能搭建一套 Restful 风格的 api,尤其适合前端接口测试使用. 只需指定一个 json 文件作为 api 的数据源即可,使用起 ...
- 在非SQL客户端使用命令行方式定期连接SQL Server 服务器并模拟用户查询操作,同时输出信息内容
一个很长的标题,实现的功能就是尽量使用非人力的方式模拟人去做一件事情,为了便于记录,将他们输出成文件方便查阅. 图形界面方式,使用微软自己的ConnMaker.exe,或者Microsoft 数据连接 ...
- SQL Server服务器上需要导入Excel数据的必要条件
SQL Server服务器上需要导入Excel数据,必须安装2007 Office system 驱动程序:数据连接组件,或者Access2010的数据库引擎可再发行程序包,这样就不必在服务器上装Ex ...
- SQL Server服务器名称与默认实例名不一致的修复方法
SQL Server服务器名称与默认实例名不一致的修复方法 分类: 个人累积 SQl SERVER 数据库复制2011-08-10 09:49 10157人阅读 评论(0) 收藏 举报 sql ser ...
- Sql Server 服务器名称\实例名称 无法连接 Server Name\Instance Name
解决步骤: 1: Sql Server是否已经启动. 2: 检查Sql Server服务器是否开启TCP/IP协议. 侦听的默认端口为1433 3: ping 数据库 ...
- web server服务器
使用最多的 web server服务器软件有两个:微软的信息服务器(iis),和Apache. 通俗的讲,Web服务器传送(serves)页面使浏览器可以浏览,然而应用程序服务器提供的是客户端应用程序 ...
- SQL Server 服务器磁盘测试之SQLIO篇
原文:SQL Server 服务器磁盘测试之SQLIO篇 数据库调优工作中,有一部分是需要排查IO问题的,例如IO的速度或者RAID级别无法响应高并发下的快速请求.最常见的就是查看磁盘每次读写的响应速 ...
- Windows Server 服务器安全配置
Windows Server 服务器安全配置 好吧,我标题党了.我只了解一些基本的安全配置.如果你是大湿,请绕道或者给予我严厉的批评让我进步谢谢. 编辑这篇文章用的编辑器编辑的,当我单击查看的时候发现 ...
随机推荐
- Nodejs的安装配置及如何在sublimetext2中运行js
Nodejs的安装配置及如何在sublimetext2中运行js听语音 | 浏览:4554 | 更新:2015-06-16 11:29 Nodejs的安装配置及如何在sublimetext2中运行js ...
- 【XSY3139】预言家 数位DP NFA
题目描述 有一个定义在 \(\{0,1,2,3,4,5,6,7,8,9\}\) 上的合规表达式,包含三种基本的操作: 结合:\(E_1E_2\) 分配:\((E_1|E_2|\ldots|E_n),n ...
- 压测过程中,获取不到redis连接池,发现redis连接数高
说明:图片截得比较大,浏览器放大倍数看即可(涉及到隐私,打了码,请见谅,如果有疑问,欢迎骚扰). 最近在压测过程中,出现获取不到redis连接池的问题 xshell连接redis服务器,查看连接数,发 ...
- Oracle jdbc 连接
所需jar包: ojdbc6.jar 下载地址:https://download.csdn.net/download/xc_oo0/10897959 示例代码: package cnblogs.com ...
- User-Agent 请求消息头
User-Agent User-Agent, 用户代理 请求消息头,其中包含了 客户机.客户端 的一些信息, 如 浏览器版本 和 类型, 操作系统的类型等. 具体解析 步骤, 推荐以下 博客文章 ...
- IrisSkin 单独控件样式设置 不使用皮肤样式
可以设置控件的Tag为this.skinEngine1.DisableTag [DefaultValue()] [Description("If you do not want skin t ...
- <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>
<%String path = request.getContextPath();String basePath = request.getScheme()+"://"+re ...
- 前端神器之jquery
jquery介绍 jQuery是目前使用最广泛的javascript函数库.据统计,全世界排名前100万的网站,有46%使用jQuery,远远超过其他库.微软公司甚至把jQuery作为他们的官方库. ...
- HDU 5984(求木棒切割期望 数学)
题意是给定一长为 L 的木棒,每次任意切去一部分直到剩余部分的长度不超过 D,求切割次数的期望. 若木棒初始长度不超过 D,则期望是 0.000000: 设切割长度为 X 的木棒切割次数的期望是 F( ...
- GO 基础
基本语法练习 打印 乘法表 package main import ("fmt") func main(){ for n:=1;n<=9;n++{ for m:=1;m< ...