前言
本文主要记录通过REST Client插件进行接口调试。
在开发过程中,前端与后端联调接口常用的工具一般使用postman或者curl命令,而本次使用REST Client插件进行接口的调试。
REST Client使用指南
安装REST Client
-
首先在VS code扩展中搜索该插件进行安装
编写.http后缀文件
本文以Hacker News Api为例进行示范
@hostname = https://hacker-news.firebaseio.com
### a story
GET {{hostname}}/v0/item/8863.json?print=pretty HTTP/1.1
content-type: application/json
定义一些常用的变量,点击Send Request发起请求,效果如下:
生成cURL
Copy Request As cURL
curl --request GET \
--url 'https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty' \
--header 'content-type: application/json'
生成代码片段
Generate Code Snippet
此处选择了 javascript -> fetch
fetch('https://hacker-news.firebaseio.com/v0/item/8863.json?print=pretty', {
method: 'GET',
headers: {
'content-type': 'application/json'
}
})
.then(response => {
console.log(response);
})
.catch(err => {
console.log(err);
});