1.全局安装json-server【可能需要管理员权限】

npm i -g json-server

2.创建文件夹jsonerver,初始化package.json文件
npm init

3.局部安装json-server
npm i json-server --save

4.修改package.json文件,配置启动方式
"scripts":{
"json:server":"json-server --watch db.json"
}

5.创建db.json文件

{
"users":[
{
"name":"zs",
"phone":"123",
"email":"zs@qq.com",
"id":1,
"age":12,
"companyId":1 // 这个companyId 使用驼峰命名的,不然是查询不到的
},
{
"name":"ls",
"phone":"234",
"email":"ls@qq.com",
"id":2,
"age":13,
"companyId":2
},
{
"name":"ww",
"phone":"345",
"email":"ww@qq.com",
"id":3,
"age":14,
"companyId":3
},
{
"name":"cl",
"phone":"456",
"email":"cl@qq.com",
"id":4,
"age":15,
"companyId":3
}
],
"companies":[
{
"id":1,
"name":"Apple",
"des":"apple is good"
},
{
"id":2,
"name":"ms",
"des":"ms is good"
},
{
"id":3,
"name":"gg",
"des":"gg is good"
}
]
}

  

6.运行
npm run json:server

localhost:3000/xxx
只能运行一个3000的端口,如果含有另一个3000端口,会运行不成功

7.运行后,可以查询如下信息

//获取所有用户信息
http://localhost:3000/users
//获取id为1的用户信息
http://localhost:3000/users/1
//获取所有公司的信息
http://localhost:3000/companies
//获取id为1的公司信息
http://localhost:3000/companies/1
//获取id为3的公司的所有用户
http://localhost:3000/companies/3/users
//获取名字为ms的公司
http://localhost:3000/companies?name=ms
//获取名字为ms和gg的公司
http://localhost:3000/companies?name=ms&name=gg
//一页显示两条数据
http://localhost:3000/companies?_page=1&_limit=2
//根据公司id的降序排序(desc 降序,asc 升序)
http://localhost:3000/companies?_sort=id&_order=desc
//获取年龄大于25的用户
http://localhost:3000/users?age_gte=25
//获取年龄小于20的用户
http://localhost:3000/users?age_lte=20
//获取年龄15到30的用户
http://localhost:3000/users?age_lte=30&age_gte=15
//搜索用户信息 q=s 搜索用户信息中含有s字符串的信息
http://localhost:3000/users?q=s
 
8.通过json-server,把jsonplacehoder的数据,提取到本地
在package.json文件中,配置
 "scripts": {
"json:server": "json-server --watch db.json",
"json:server:remote": "json-server http://jsonplaceholder.typicode.com/db" //添加这行
},

  重新运行,npm run json:server:remote,可以访问到jsonplaceholder中的数据

配置json-server的更多相关文章

  1. Apache 配置ArcGIS server/portal 反向代理

    背景 处于安全,负载均衡,访问加速等原因会对服务器启用反向代理.arcgis for server的默认的访问地址为http://server:6080/arcgis.这个时候端口和实例名都暴露了.可 ...

  2. json:server 本地搭建

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

  3. Postgresql 简单配置 (ubuntu server 14.04.3)

    安装和配置 ubuntu server 已经自动安装了progresql,故安装步骤就省略 初始postgresql没有密码,不能使用,需要先设置密码,命令(从网上随意找的)如下: sudo su p ...

  4. springMVC配置Json

    步骤1:将json包引入工程中,分别是:jackson-annotations-2.7.0.jar,jackson-core-2.7.0.jar,jackson-databind-2.7.0.jar ...

  5. 配置SQL Server去使用 Windows的 Large-Page/Huge-Page allocations

    配置SQL Server去使用 Windows的 Large-Page/Huge-Page  allocations 目录表->页表->物理内存页 看这篇文章之前可以先看一下下面这篇文章 ...

  6. 配置sql server 2000以允许远程访问 及 连接中的四个最常见错误

    地址:http://www.cnblogs.com/JoshuaDreaming/archive/2010/12/01/1893242.html 配置sql server 2000以允许远程访问适合故 ...

  7. 配置SQL Server 2008 R2 Reporting Services

    记录如何在本地配置SQL Server 2008 R2 Reporting Services,笔者环境为Windows 7 64位 + SQL Server 2008 R2 一.准备工作 其实准备工作 ...

  8. Ubuntu配置ssh server

    SSH-Server配置指南 一.SSH简介 SSH (Secure Shell)是一个应用程序中提供安全通信的协议,通过SSH协议可以安全地访问服务器,因为SSH 具有成熟的公钥加密体系,在数据进行 ...

  9. 配置SQL Server 2008服务器

    怎么配置SQL Server 2008服务器_百度经验 http://jingyan.baidu.com/article/9faa7231a922c1473c28cb23.html 1.验证安装是否成 ...

  10. 第三篇——第二部分——第五文 配置SQL Server镜像——域环境SQL Server镜像日常维护

    本文接上面两篇搭建镜像的文章: 第三篇--第二部分--第三文 配置SQL Server镜像--域环境:http://blog.csdn.net/dba_huangzj/article/details/ ...

随机推荐

  1. Reactive Programming

    Reactive的表现 Reactive 规范是 JVM Reactive 扩展规范 Reactive Streams JVM,而 Reactive 实现框架则是最典型的实现: Reactive St ...

  2. Taro开发之城市选择器(带坐标)

    要写个城市选择器能返回对应的城市(这里只定义到了地级市),同时返回坐标系,参考了网上资料,下面就看看具体代码吧 import Taro, { Component } from '@tarojs/tar ...

  3. 如何查看和清除svn登录信息

    切换svn登录用 点击clear,出现用户信息,勾选后点击ok 即清除 .下次访问svn需要重新登录

  4. CentOS7 PHP+Redis实现Session共享

    先yum简单的安装redis wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/epel-7.repo ...

  5. 长短steamId互转

    /** * steam_id转换account_id * @param $steamId * @return mixed */ public static function formatAccount ...

  6. Java集合中List,Set以及Map等集合体系详解

    转载请注明出处:Java集合中List,Set以及Map等集合体系详解(史上最全) 概述: List , Set, Map都是接口,前两个继承至collection接口,Map为独立接口 Set下有H ...

  7. Huawei BGP和OSPF双边界重分布(一)

    网络拓扑: PS:本例使用明细前缀列表双边界引入 S5700-LSW1 ================================================================ ...

  8. P1579哥德巴赫猜想

    写来自己学习用~ 题目内容: 1742年6月7日哥德巴赫写信给当时的大数学家欧拉,正式提出了以下的猜想:任何一个大于9的奇数都可以表示成3个质数之和.质数是指除了1和本身之外没有其他约数的数,如2和1 ...

  9. input下拉框

    用Html5和css.js写的,引用的bootstrap和jquery文件请各位看客自己去下载

  10. hystrix参数详解

    hystrix.command.default和hystrix.threadpool.default中的default为默认CommandKey Execution相关的属性的配置: hystrix. ...