mynote/jetbrains/http-client.md
2020-01-13 20:05:35 +08:00

88 lines
1.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# HTTP-Client-Editor of jetbrains
## 环境描述文件
- http-client.private.env.json 存储敏感信息的环境文件
```json
{
"env1": {"auth": ""},
"env2": {
"auth": "",
"key": ""
}
}
```
- http-client.env.json 存储普通信息的环境文件
```json
{
"env1": {
"base_url": ""
},
"env2": {}
}
```
## 请求描述文件
- *.http
```http
### 描述信息 (每个请求要以三个#开头)
# get请求
GET {{base_url}}/first
Authorization: Basic {{auth}}
```
```http
### post 请求
POST {{base_url}}/second
Accept: application/json
> {%
client.log(response.body)
%}
```
- 变量由{{}}给出
1. 由环境描述文件给出, 如{{auth}},{{base_url}}
2. 由特定函数给出,如[{{$timestamp}} {{$uuid}} {{randomInt}}](https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html#dynamic-variables)
3. 由[返回处理脚本](https://www.jetbrains.com/help/idea/http-client-in-product-code-editor.html#)给出
```bash
> {%
client.log(response.body)
client.global.set("id", response.body.data[0].id)
# 设置环境变量id
%}
```
```bash
> ./temp.js
```
## 执行
- 在每个请求左侧有个绿色箭头 可以选择执行环境, .json 和 .http 在同一目录下
![image-20200112231911921](/Users/light/workspace/mynote/jetbrains/image-20200112231911921-8842506.png)
- 编辑窗口顶部点击Run All Requests in File 会顺序执行所有请求
![image-20200112232328295](/Users/light/workspace/mynote/static/img/image-20200112232328295.png)