rest client 是 vscode 中类似 Postman 的 api 接口请求利器。

创建 http 文件

使用 .http 结尾的文件可以被 rest-client 插件识别

注意:

  1. ### 分割接口
  2. @uri 可以定义请求前缀,且不能加 ""
  3. 示例里的接口服务器地址在国外,测试时可能会发生错误,发生错误时多试几次即可
api.http
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
@uri=https://jsonplaceholder.typicode.com

###
GET {{uri}}/posts/1

###
GET {{uri}}/posts

###
POST {{uri}}/posts
Content-Type: application/json;charset=UTF-8

{
"title": "foo",
"body": "bar",
"userId": 1
}

###
PUT {{uri}}/posts/1
Content-Type: application/json;charset=UTF-8

{
"id": 1,
"title": "foo",
"body": "bar",
"userId": 1
}

###
PATCH {{uri}}/posts/1
Content-Type: application/json;charset=UTF-8

{
"title": "foo",
}

###
DELETE {{uri}}/posts/1