当前位置:网站首页>Idea rest client, yes, I haven't opened postman yet
Idea rest client, yes, I haven't opened postman yet
2020-11-09 12:28:00 【S_uspend】
1. brief introduction
IDEA It provides test interface tools , rest-client/http client, It's very powerful , In my daily use , It can be done without opening postman The degree of . The entrance is as follows :

<center> Figure 1 Open mode </center>
Click on Test RESTful Web Service Yes open Rest Client Tools , Can be understood as a use of IDEAUI Interface testing tool for , Relatively visual , Fill in the value directly according to the actual demand , Click the button in the upper left corner to start the test .

<center> Figure 2 rest client</center>
The second option in Figure 1 is Open Http Requests Collection It's just Today's point , You can go directly through .http Suffix file to request the interface . Except in the toolbar , You can do it yourself anywhere new One came out ( chart 4), Or click on the Yellow bottom in Figure 2 Convert request to the new format , Will also be in Scratches and consoles Under the Scratches Folder Generate a .http file ( Figure 5 )

<center> Figure 3 http client</center>

<center> Figure 4 </center>

<center> Figure 5 </center>
2. http client
Let's talk about it http client Use , The simple understanding is http Requested parameters , You can define it here .
Just entering the file will give you an example , The first line is easy to understand , Select the request method (GET、POST、PUT etc. ) as well as Request address , This is required ; The second line doesn't have to start with , If you don't give it, you can give it by default according to your request mode
GET http://localhost:8080/resources
Accept: */*
Cache-Control: no-cache
2.1 Ordinary request
After the request is successful, the content of the request will be displayed in the lower console , And the result , And in .http There is a history record below the corresponding request of the file , Convenient view ( As shown in figure 6 )

<center> Figure 6 http client Running effect </center>
2.2 Variable request
Systems are often deployed in different environments ,http client It also supports modifying parameters according to different environments , The supported parameters are :
- request ip, Ports and paths
- Query parameters or values
- The value of the request header
- Provide an arbitrary value for the body of the request in an external file
Supported environment variable definition files have specific naming methods , And need to talk to .http The files are in the same directory (Scratches and consoles Under the folder, only normal requests can be made ), There are also requirements for naming , Need is one of the following :
- rest-client.env.json
- http-client.env.json
- rest-client.private.env.json
- http-client.private.en.json
In the above-mentioned documents private Does not mean that it is a private document , It might include a password , token , Sensitive information such as certificates , By default , This file is added to VCS Ignore the file list . Use as follows ( The content is Json Format ):

<center> Figure 7 Environment variable file settings </center>

<center> Figure 8 Run time selection </center>
As shown in Figure 7 Figure 8 , After setting the environment variables, the runtime can select the relevant environment variables and pass them into the request , Just run directly
3. Use tips
3.1 grammar
- Annotation use
//perhaps# - Separate request with
### - If you don't want to generate logs
- Script With
>start , Write logic in{% %}in , You can call client object

<center> Figure nine Do not log </center>
3.2 Shortcut key
| Shortcut key | explain |
|---|---|
| gtr | Generate a get request |
| gtrp | Generate a get request , Additional parameters |
| ptr | Generate a post request , The format is application/json |
| ptrt | Generate a post request , The format is application/x-www-form-urlencoded |
| mptr | Generate a post request , Form submission |
| fptr | Generate a post request , Upload files |
###
# gtr
GET http://localhost:80/api/item
Accept: application/json
###
# gtrp
GET http://localhost:80/api/item?id=99
Accept: application/json
###
# prt
POST http://localhost:80/api/item
Content-Type: application/json
{}
###
#ptrp
POST http://localhost:80/api/item
Content-Type: application/x-www-form-urlencoded
id=99&content=new-element
###
# mptr
POST http://localhost:80/api/item
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="field-name"
field-value
--WebAppBoundary--
###
# fprt
POST http://localhost:80/api/item
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="field-name" filename="file.txt"
< ./relative/path/to/local_file.txt
--WebAppBoundary--
###
3.3 Script
You can add scripts to the request , Print or store information , You can use scripts to store some result variables , And then reference it like an environment variable .

<center> Figure ten Script example </center>
If you use script printing , As a result, an option box appears on the console , Display printed content , Like the one below Respinse Handler

3.4 Look at examples
IDEA stay .http The right side of the file already gives us a lot of examples , And easy to use , When you can't do it , You can also refer to . Also available from cURL Convert to .http File recognizable request function .

This article by the blog one article many sends the platform OpenWrite Release !
版权声明
本文为[S_uspend]所创,转载请带上原文链接,感谢
边栏推荐
- Configure switch trunk interface traffic local priority forwarding (cluster / stack)
- 关于无相互作用极化率的计算
- 从汇编的角度看pdb文件
- EFF 认为 RIAA 正在“滥用 DMCA”来关闭 YouTube-DL
- Wechat circle
- 分库分表的 9种分布式主键ID 生成方案,挺全乎的
- Interview summary on November 7, 2020 (interview 12K)
- PAT_甲级_1074 Reversing Linked List
- JVM学习(五) -执行子系统
- Chrome browser engine blink & V8
猜你喜欢

一个简单的能力,决定你是否会学习!

Tidb x micro banking reduces time consumption by 58%, and distributed architecture helps to realize inclusive finance

Vscode plug-in configuration pointing North

服务应用 ClockService安卓实现闹钟

iPhone“连到系统上的设备没有发挥作用”原因分析及解决方法 20200105

IDEA rest-client,会了它我还没打开过postman

从编码、网络传输、架构设计揭秘腾讯云高质量、高可用实时音视频技术实践...

inet_pton()和inet_ntop()函数详解

Android rights

Oh, my God! Printing log only knows log4j?
随机推荐
手写Koa.js源码
导师制Unity网课 双十一优惠报名进行中
未来中国电信将把云计算服务打造成为中国电信的主业
As a user, you can't get rid of the portrait!
SQL statement to achieve the number of daffodils
Android 集成支付的四部曲
Understanding data structures starts with this article~
Chrome browser engine blink & V8
一个简单的能力,决定你是否会学习!
VisualStudio(Mac)安装过程笔记
外贸自建网站域名的选择— Namesilo 域名购买
Vscode plug-in configuration pointing North
Android NDK development and actual combat WeChat official account 2-D code detection
Analysis of the source code of ThinkPHP facade
In the future, China Telecom will make cloud computing service the main business of China Telecom
线上服务的FGC问题排查,看这篇就够了!
A simple way to realize terminal text paste board
Adobe Experience Design /Xd 2020软件安装包(附安装教程)
从编码、网络传输、架构设计揭秘腾讯云高质量、高可用实时音视频技术实践...
分库分表的 9种分布式主键ID 生成方案,挺全乎的