Using IntelliJ IDEA REST Client for API Testing: Features, Scripts, and Environment Management
This article explains how IntelliJ IDEA REST Client can replace Postman for API debugging by offering integrated request consoles, history logs, environment variable support, scriptable assertions, and token handling, providing a unified tool for backend developers to test and share HTTP requests efficiently.
API debugging is an essential skill for developers, and while Postman has been a popular choice, IntelliJ IDEA REST Client offers all of Postman's features plus additional capabilities, making it a superior integrated solution.
Comparison with Postman
IDEA REST Client includes every function of Postman, such as a REST console and request history.
It allows developers to stay within a single IDE for both coding and debugging.
It supports environment configuration, response assertions, and scripting.
Request configurations can be stored in files and shared across the project.
IDEA REST Client Console
Access the console via Tools → HTTP Client → Test RESTFUL Web Service . The interface provides request method selection, parameter entry, and header configuration, including a button for Basic Authorization that opens a dialog to fill username and password.
History Request Log
IDEA automatically saves the last 50 requests in .idea/httpRequests/http-requests-log.http , allowing quick navigation and re‑execution of previous calls.
Building HTTP Request Scripts
Requests can be saved as .http or .rest files. The following example demonstrates the script syntax:
### 演示POST请求
POST {{baseUrl}}}get?show_env=1
Accept: application/json
{
"name":"a"
}
### 演示GET请求
GET {{baseUrl}}}/post
Content-Type: application/x-www-form-urlencoded
id=999&value=contentEach request is separated by ### , with URL and headers placed directly after the method line, and body or query parameters on new lines.
Environment Variables
Placeholders like {{baseUrl}} are resolved from an .http ‑side configuration file, e.g.:
{
"uat": {
"baseUrl": "http://gateway.xxx.cn/",
"username": "",
"password": ""
},
"dev": {
"baseUrl": "http://localhsot:8888/",
"username": "",
"password": ""
}
}When executing a request, IDEA prompts you to select the desired environment (e.g., dev, uat).
Result Assertions
IDEA REST Client supports scriptable assertions to turn the tool into a testing framework:
### Successful test: check response status is 200
GET https://httpbin.org/status/200
> {%
client.test("Request executed successfully", function() {
client.assert(response.status === 200, "Response status is not 200");
});
%}Token Handling Example
### 演示POST请求
POST https://httpbin.org/post
Content-Type: application/json
{
"user": "admin",
"password": "123456"
}
> {% client.global.set("auth_token", response.body.json.token); %}
### 演示GET请求
GET https://httpbin.org/headers
Authorization: Bearer {{auth_token}}After the authentication request, the returned token is stored in a global variable and reused in subsequent calls via the {{auth_token}} placeholder.
Conclusion
While Postman remains a solid tool, IDEA REST Client provides an integrated, scriptable, and shareable environment for API testing, making it a compelling choice for backend developers.
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.