php rest client,比 Postman 更好用的 api 工具 Vscode rest client

1. 使用步骤

在 VS Code 新建一个以 .http 或者 .rest 结尾的文件,填入你的 HTTP 请求,点击 Send Request,或者右键选择 Send Request,或者直接用快捷键 Ctrl + Alt + R ,你的 REST API 就执行了,然后 API Response 就会显示在右边区域。

062ce0ff9f6d

image

编写 api 文档可以直接用 charles 抓包,然后选择 Contents -> Raw ,拷贝其中的内容直接放到 .http 文件中即可

2. HTTP 请求

使用 @apiHost 的 apiHost 变量做为动态域名

@apiHost = xxx.xxxdm.net

Get 请求

http://{{ apiHost }}//vx/list?offset=0&limit=20

GET /app/xx/index.php?r=xxx/ddd&latitude=&accessToken=sfa&longitude=&accessSecret=jjhf HTTP/1.1

X-Client: android/3.5.3

Host: {{ apiHost }}

Accept-Encoding: gzip

User-Agent: okhttp/3.8.0

Connection: keep-alive

Post 请求

content-type 为 application/x-www-form-urlencoded

POST /vx/like/count HTTP/1.1

Host: {{ xxxHost }}

Content-Type: application/x-www-form-urlencoded; charset=utf-8

X-Auth-Token: sdfa

Content-Length: 95

Accept: application/json, text/plain,image/webp, */*

User-Agent: djxxx/4.6.8 (xxx.ddd.xxxdm; build:1.0.0; iOS 13.5.0) Aladire/4.9.1

Accept-Language: zh-Hans-CN;q=1.0

X-Client: iOS/2.1.2-beta

Accept-Encoding: gzip;q=1.0, compress;q=0.5

Connection: keep-alive

accessSecret=jjhf&accessToken=sfa&tid=123

content-type 为 application/json

POST http://dummy.restapiexample.com/api/v1/create HTTP/1.1

content-type: application/json

{

"name":"Hendry",

"salary":"61888",

"age":"26"

}

content-type 为其他

参考文档

3. 一个文件包含多个请求

通过 ### 分隔符,同一个 HTTP 文件里可以涵盖多个HTTP请求。不像Postman,不同的HTTP请求需要放在不同的tab里

062ce0ff9f6d

image

4. 动态域名

使用 @xxxHost 的 xxxHost 变量做为动态域名

@xxxHost = xxx.xxxdm.net

使用动态域名:

http://{{ xxxHost }}//v2/acg/series-list?offset=0&limit=20&zq_id=4&zqxl_id=1

GET /mobcent/app/web/index.php?r=xxx/atuserlist&latitude=&accessToken=sfa&longitude=&accessSecret=jjhf HTTP/1.1

X-Client: android/3.5.3

Host: {{ apiHost }}

Accept-Encoding: gzip

User-Agent: okhttp/3.8.0

Connection: keep-alive

5. 代码生成

可以方便地通过 Generate Code Snippet 命令来把 HTTP 请求生成出不同编程语言的代码:JavaScript, Python, C, C#, Java, PHP, Go, Ruby, Swift 等等主流语言。

062ce0ff9f6d

image

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值