笔者平日用 Visual Studio Code 进行全栈开发,有的时候需要用 Postman 进行 API 测试。最近发现了一个好用的 Visual Studio Code 扩展:Rest Client,能部分取代 Postman. 特地分享给大家:

安装完毕后,在 Visual Studio Code 工程里创建一个任意名称的文件,只要满足 .http 后缀即可。将如下内容粘贴进去,即可实现 Postman 里通过 HTTP POST 调用某 Restful API 的目的:
POST https://example.com/comments HTTP/1.1
content-type: application/json
{
"name": "sample",
"time": "Wed, 21 Oct 2015 18:27:50 GMT"
}

点击上图的 Send Request 超链接,即可在 Visual Studio Code 编辑区域的右边,看到该 API 的响应。

直接右键点击 .http 文件编辑区域,从右键菜单里选择 Send Request 也能达到同样的目的。

我们从上图右键菜单里还能发现 Generate Code Snippt 的选项,即自动生成该 HTTP 请求的调用代码。
可以选择基于哪种编程语言生成调用代码。比如我选择 Node.js:

然后贴心的给出了基于 Node.js 哪一种 HTTP 工具库生成调用代码:

下图是基于 Node.js Request 工具库生成的调用代码。能为开发人员节省一些手动敲代码的时间。

在 Visual Studio Code 状态栏里,鼠标 hover 上 response time,能看到这个时间的具体组成。

对于 Postman 的基本功能,该扩展足以实现。对于 Postman 的一些高级功能,比如自动调用一系列具有先后逻辑顺序的 Postman 请求,是否也能用该扩展实现,还有待进一步研究。
更多Jerry的原创文章,尽在:"汪子熙":

网友评论