windows搭建json-server快速方法
JSON-Server 是一个 Node 模块,运行 Express 服务器,你可以指定一个 json 文件作为 api 的数据源。
一、下载并安装node.js

安装完后输入 node --version 检查是否安装成功
二、安装json-server
1.新建项目 mkdir json-demo && cd json-demo

2.初始化项目 npm init 或 npm init --yes

前者需都按回车,

3.安装 npm install json-server --save 或 npm install --save-dev json-server

4.在项目根目录(C:\Users\Administrator\json-demo)下,新建一个 JSON 文件db.json
{
"users": [
{
"name": "tt",
"phone": "123456789",
"email": "111@qq.com",
"age": "20",
"id": 1,
"companyId": 1
},
{
"name": "dede",
"phone": "123456789",
"email": "222@qq.com",
"age": "30",
"id": 2,
"companyId": 2
},
{
"name": "wf",
"phone": "123456789",
"email": "333@qq.com",
"age": "23",
"id": 3,
"companyId": 3
},
{
"name": "mj",
"phone": "123456789",
"email": "444@qq.com",
"age": "45",
"id": 4,
"companyId": 3
}
],
"companies": [
{
"id": 1,
"name": "Apple",
"description": "Apple lalala!"
},
{
"id": 2,
"name": "Microsoft",
"description": "Microsoft lalala!"
},
{
"id": 3,
"name": "Google",
"description": "Google lalala!"
}
]
}

5. 把db.json文件托管成一个 web 服务 json-server --watch --port 53000 db.json

6.打开浏览器输入 http://localhost:53000/companies访问成功如下

7. 如果关闭了cmd窗口,再次打开可以再次输入 json-server --watch --port 53000 db.json
8. 查看相关内容
// 获取所有用户信息
http://localhost:53000/users // 获取id为1的用户信息
http://localhost:53000/users/1 // 获取公司的所有信息
http://localhost:53000/companies // 获取单个公司的信息
http://localhost:53000/companies/1 // 获取所有公司id为3的用户
http://localhost:53000/companies/3/users // 根据公司名字获取信息
http://localhost:3000/companies?name=Microsoft // 根据多个名字获取公司信息
http://localhost:53000/companies?name=Microsoft&name=Apple // 获取一页中只有两条数据
http://localhost:53000/companies?_page=1&_limit=2 // 升序排序 asc升序 desc降序
http://localhost:53000/companies?_sort=name&_order=asc // 获取年龄30及以上的
http://localhost:53000/users?age_gte=30 // 获取年龄在30到40之间
http://localhost:53000/users?age_gte=30&age_lte=40 // 搜索用户信息
http://localhost:53000/users?q=h h指的是查询的首字母
参考
2 一分钟内搭建全web的API接口神器json-server详解
windows搭建json-server快速方法的更多相关文章
- json server的简单使用(附:使用nodejs快速搭建本地服务器)
作为前端开发人员,经常需要模拟后台数据,我们称之为mock.通常的方式为自己搭建一个服务器,返回我们想要的数据.json server 作为工具,因为它足够简单,写少量数据,即可使用. 安装 首先需要 ...
- Windows 2008 Server搭建Radius服务器的方法
原地址:http://service.tp-link.com.cn/detail_article_1113.html (图拷贝不过来) Windows 2008 Server搭建Radius服务器的方 ...
- 在Windows Server 2012 R2中搭建SQL Server 2012故障转移集群
需要说明的是我们搭建的SQL Server故障转移集群(SQL Server Failover Cluster)是可用性集群,而不是负载均衡集群,其目的是为了保证服务的连续性和可用性,而不是为了提高服 ...
- Windows Server 2012搭建SQL Server Always On踩坑全记录
Windows Server 2012搭建SQL Server Always On踩坑全记录 环境信息: Windows Server 2012 R2 Sql Server 2012 整个搭建集群的过 ...
- 在windows上搭建git server Gitblit
在Windows上搭建Git Server 第1步:下载Java并安装Java.我这里下载的是jdk1.7.0_79 第2步:配置Java环境变量 右键” 计算机” => ”属性” => ...
- windows上zend server安装 报The server encountered an internal error or misconfiguration and was unable to complete your request -解决方法 摘自网络
windows上zend server安装完成后报如下错误: Internal Server Error The server encountered an internal error or m ...
- json:server 本地搭建
做个记录, 第一步,我们新建一个文件夹. 第二步,打开文件夹,执行git,没有git可以下载一个.或者用命令行工具进入到这个文件夹! 第三步,初始化json 在git里执行npm init --ye ...
- 从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn)
从0开始搭建SQL Server AlwaysOn 第三篇(配置AlwaysOn) 第一篇http://www.cnblogs.com/lyhabc/p/4678330.html第二篇http://w ...
- Linux 搭建SVN server
一. SVN 简单介绍 Subversion(SVN) 是一个开源的版本号控制系統, 也就是说 Subversion 管理着随时间改变的数据. 这些数据放置在一个中央资料档案库 (repository ...
- 第三篇——第二部分——第二文 计划搭建SQL Server镜像
原文:第三篇--第二部分--第二文 计划搭建SQL Server镜像 本文紧跟上一章:SQL Server镜像简介 本文出处:http://blog.csdn.net/dba_huangzj/arti ...
随机推荐
- AtCoder Regular Contest 092 B Two Sequences
题目大意 给定两个长为 $n$ 个整数序列 $a_1, \dots, a_n$ 和 $b_1, \dots, b_n$ .求所有 $a_i + b_j$($1\le i, j\le n$)的 XOR ...
- hdu 4258 斜率DP
思路:dp[i]=dp[j]+(num[i]-num[j+1])^2; #include<iostream> #include<cstring> #include<alg ...
- JAVA会员生日和密码
import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import ja ...
- (...)ES6三点扩展运算符
扩展运算符将一个数组转为用逗号分隔的参数序列 console.log(...[a, b, c]) // a b c 用于: 1 将一个数组,变为参数序列 let add = (x, y) => ...
- POJ3687 Labeling Balls
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13645 Accepted: 3955 Description Wind ...
- 关于Struts2中param的作用
1.页面传参与配置传参的区别: 如果页面Form表单的参数在Action类中有相应的setter方法,则会优先取页面Form表单传过来的值,如果页面没有该属性同名的参数,则会从配置文件中取同名的参数值 ...
- hdu 3074(线段树)
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 转载——Java与WCF交互(一)补充:用WSImport生成WSDL的Java客户端代码
在<Java与WCF交互(一):Java客户端调用WCF服务>一文中,我描述了用axis2的一个Eclipse控件生成WCF的Java客户端代理类,后来有朋友建议用Xfire.CXF,一直 ...
- 解决dvajs使用BrowserHistory路由模式后仍然会出现hash(哈希)
在dvajs中,如果你在初始化dva对象的时候不作任何处理,那么你就会发现即使你是用了BrowserRouter来作为Router url中也是会出现#/.解决方法也很简单: 使用前先手动安装下 hi ...
- grep的简单理解
概述: grep最早由肯·汤普逊写成.原先是ed下的一个应用程序,名称来自于g/re/p(globally search a regular expression and print,以正则进行全域查 ...