当前位置:网站首页>使用json-server快速搭建本地数据接口
使用json-server快速搭建本地数据接口
2022-08-04 11:12:00 【lyudev】
官方网站:https://github.com/typicode/json-server
终端输入:sudo npm install -g json-server
创建一个json文件
{
"user": [
{
"id": 1,
"name": "james",
"phone": "333-444-555",
"email": "[email protected]",
"age": 30,
"companyid": 1
},
{
"id": 2,
"name": "curry",
"phone": "333-444-555",
"email": "[email protected]",
"age": 31,
"companyid": 2
},
{
"id": 3,
"name": "davis",
"phone": "333-444-555",
"email": "[email protected]",
"age": 3,
"companyid": 3
},
{
"id": 4,
"name": "jackson",
"phone": "333-444-555",
"email": "[email protected]",
"age": 33,
"companyid": 3
},
{
"name": "bryant",
"phone": "333-444-555",
"email": "[email protected]",
"age": 41,
"companyid": 4,
"id": 5
}
],
"company": [
{
"id": 1,
"companyname": "apple",
"des": "apple is good"
},
{
"id": 2,
"companyname": "huawei",
"des": "huawei is good"
},
{
"id": 3,
"companyname": "oppo",
"des": "oppo is good"
},
{
"id": 4,
"companyname": "alibaba",
"des": "alibaba is good"
}
]
}
get请求
# 启动json-server
json-server --watch db.json
# 获取所有用户
http://localhost:3000/user
# 获取用户id为1的
http://localhost:3000/user/1
# 获取所有公司
http://localhost:3000/company/
# 获取公司id为1的
http://localhost:3000/company/1
# 根据公司名字获取公司
http://localhost:3000/company?companyname=apple
# 根据多个公司名字获取
http://localhost:3000/company?companyname=apple&companyname=alibaba
# 获取一个页面显示两条信息
http://localhost:3000/company?_page=1&_limit=2
# 升序排序
http://localhost:3000/company?_sort=id&_order=asc
# 降序排序
http://localhost:3000/company?_sort=id&_order=desc
# 获取年龄大于30的
http://localhost:3000/user?age_gte=30
# 获取年龄区间的
http://localhost:3000/user?age_gte=3&age_lte=31
# 搜索姓名
http://localhost:3000/user?q=cu
post,patch,delete,需要下载postman,官方网站:[https://www.postman.com/downloads/](https://www.postman.com/downloads/),设置Headers,key是Content-Type,value是application/json,Body选择raw
{"name": "bryant", "phone": "333-444-555","email":"[email protected]","age":41,"companyid":4}
边栏推荐
猜你喜欢
再次搞定 Ali 云函数计算 FC
*iframe*
Use pytest hook function to realize automatic test result push enterprise WeChat
AWS Lambda相关概念与实现思路
Graphical Hands-on Tutorial--ESP32 OTA Over-the-Air Upgrade (VSCODE+IDF)
ROI LTV CPA ECPM体系讲解
Small program containers accelerate the construction of an integrated online government service platform
audio_policy_configuration.xml配置文件详解
美摄问答室|美映 VS 美摄云剪辑
MATLAB程序设计与应用 3.2 矩阵变换
随机推荐
知网网站地址更换
MySql数据库入门的基本操作
WPF 截图控件之画笔(八)「仿微信」
【虹科案例】基于3D相机组装家具
Heap Sort
Apache Calcite 框架原理入门和生产应用
命令模式(Command)
单调栈一些题目练习
Mysql数据类型
Xilinx VIVADO 中 DDR3(Naive)的使用(3)仿真测试
强烈推荐一款优秀且通用的后台管理系统
*iframe*
123
Small program containers accelerate the construction of an integrated online government service platform
热成像测温的原理是什么呢?你知道吗?
Super Learning Method
数字知识库及考学一体化平台
AWS Lambda related concepts and implementation approach
Using .NET to simply implement a high-performance clone of Redis (2)
北京大学,新迎3位副校长!其中一人为中科院院士!