当前位置:网站首页>利用json-server在本地创建服务器请求
利用json-server在本地创建服务器请求
2022-04-23 14:06:00 【万伏小太阳】
在前后端分离开发时,前后端进度不一致时,而前端需要测试一下请求接口写的怎么样的,后端还没有给你接口,你可以找网上一些免费的api请求地址,比如:百度api啥的。但是这些api请求通常只能测试get请求,对于post请求测试效果并不明显,这个时候我们可以利用一下json-server,花几分钟在本地运行一个小型服务器接口。
接下来介绍一下过程:
安装json server这个包
创建文件夹json-server
并在此目录下安装,执行下面这条指令:
npm install -g json-server
建立文件db.js
写入一下内容,代表json格式的数据
{
"posts": [
{
"id": 1, "title": "json-server", "author": "typicode" }
],
"comments": [
{
"id": 1, "body": "some comment", "postId": 1 }
],
"profile": {
"name": "typicode" }
}
执行指令:
json-server --watch db.json
运行成功之后:
在3000端口开启了一个服务器,api请求地址为
http://localhost:3000
可以通过axios库来发起请求,在基础api URL后面可以接一些参数。
版权声明
本文为[万伏小太阳]所创,转载请带上原文链接,感谢
https://blog.csdn.net/weixin_51009975/article/details/124204645
边栏推荐
- Wechat applet communicates with low-power Bluetooth - receives data sent by hardware (IV)
- leetcode--357. Count the number of different figures
- 数据库DbVisualizer Pro报文件错误,导致数据连接失败
- 对List集合进行分页
- logback-logger和root
- 星界边境文本自动翻译机(高级版)使用说明
- Autumn recruitment in 2021, salary ranking No
- 修改ddt生成的测试用例名称
- RobotFramework 之 用例标签机制
- 报表FCRA考试题集及答案(错了11题)
猜你喜欢
linux安装mysql后修改密码
基于CM管理的CDH集群集成Phoenix
DeepinV20安装Mariadb
poi操作word模板替换数据并且导出word
Chapter I review of e-commerce spike products
Wechat applet initializes Bluetooth, searches nearby Bluetooth devices and connects designated Bluetooth (I)
修改ddt生成的测试用例名称
Use of WiFi module based on wechat applet
教育行业云迁移最佳实践:海云捷迅使用HyperMotion云迁移产品为北京某大学实施渐进式迁移,成功率100%
As a junior college student, I studied hard in closed doors for 56 days, won Ali offer with tears, five rounds of interviews and six hours of soul torture
随机推荐
Prediction of tomorrow's trading limit of Low Frequency Quantization
关于密匙传递的安全性和数字签名
RecyclerView高级使用(二)-垂直拖拽排序的简单实现
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
Wechat applet positioning and ranging through low-power Bluetooth device (2)
PyMySQL
Chrome插件 之 Selenium IDE、XPath 安装
金融行业云迁移实践 平安金融云整合HyperMotion云迁移解决方案,为金融行业客户提供迁移服务
Logging模块
RecyclerView高级使用(一)-侧滑删除的简单实现
更改plsql工具栏的图标大小
在MAC上安装mysql
findstr不是内部或外部命令解决方法
PySide2
快速安装mongodb
Idea控制台乱码解决
How QT designer adds resource files
Detailed tutorial on the use of setinterval timing function of wechat applet
Wechat applet obtains login user information, openid and access_ token
Use of WiFi module based on wechat applet