Vscode uses restClient to implement various http requests
First, install the plug-in
First, we need to search for the rest client in the extension of vscode, and then install it, which I have already installed here.
After installation, we can use the rest client plugin to perform various http operations.
Two, simple entry
First, we need to create a .http file. After creating the file, type the following command in the file
GET www.baidu.com HTTP/1.1
After typing the command, the word Send Request appears on it, which can be clicked, and after clicking, the return result after sending the request will appear on the right.
When we need to use multiple requests, use ### to separate them as shown below:
At this point, we use the rest Client plug-in to get started. Next comes the advanced stage.
Three, environment variables
Using the rest client plug-in, we can define environment variables so that we can switch between different environments. First, we need to find the settings.json file. As shown in the figure below, we click the setting button in the lower left corner to enter the settings, find and edit in settings.json, and
click Enter, you can enter the edit. As shown below:
The red box in the figure is the configuration of environment variables. I have configured three environments, namely local, dev and qa. $shared is shared and can be used in any environment. The configuration is as follows:
"rest-client.environmentVariables": {
"$shared": {
"version": "v1"
},
"local": {
"uacUrl": "http://dev-i.liyouqing.com",
"baseUrl": "http://localhost:8080",
"userId": "***********************",
"clientId": "***********************",
"loginAccount": "*********",
"password": "0000"
},
"dev": {
"uacUrl": "http://dev-i.liyouqing.com",
"baseUrl": "http://dev-i.liyouqing.com",
"userId": "***********************",
"clientId": "***********************",
"loginAccount": "15212340822",
"password": "00000"
},
"qa": {
"uacUrl": "http://qa-i.liyouqing.com",
"baseUrl": "http://qa-i.liyouqing.com",
"userId": "*********",
"clientId": "*********",
"loginAccount": "*********",
"password": "***********************"
}
}
Fourth, define variables and use environment variables and return data as variables
We can use variables when using the rest client request, as shown in the figure below:
We define an orgCode variable and use it as the orgCode data in the header of the request when requesting. By {
{baseUrl}} the value in the environment variable is used. So how do we choose environment variables? As shown in the figure below:
When clicking the environment location in the lower right corner, a drop-down box of existing environment variables will appear above, and we can select environment variables at this time. So, how do we use the data returned by the interface? As shown below:
Before requesting data, we defined a # @name grant. When the request is over, we can use grant to get the returned data, the json data returned by me.
Five, various requests
post request
As shown in the figure below, the red frame part is the body part of the post request, which of the above is the data in the header.
file upload request
As shown in the figure below, file upload is also relatively simple
Six, other functions
code generation
We can generate code according to the request, put the mouse on the request, and right click. As shown below:
Then, we select the generated language, as shown below:
Then the code for the corresponding language request is generated, isn't it very convenient? As shown below:
Summarize
Since I used the rest client plugin of vscode, I haven't used postman for a long time.