领导想 POSTMAN 建个组,这样就能共享请求了,结果只能加5个,超了得交钱,我说,何不 IDEA HTTP Request 呢,据说很香。
- GET http://localhost:8090/persons/all
- GET http://localhost:8090/persons/all
- Accept-Language:en-US,en;q=0.9
- Authorization:BasicQWxhZGRpbjpvcGVuIHNlc2FtZQ==
- Cookie: name=value; name2=value2; name3=value3
- POST http://localhost:8090/persons/add/
- Content-Type: application/json
-
- {
- "name": "JohnDoe",
- "age": 29
- }
- POST http://localhost:8090/persons/add/
- Content-Type: application/json
-
- < person.json
rest-client.env.json
- {
- "local":{
- "host":"localhost"
- },
- "development":{
- "host":"dev.example.com"
- },
- "production":{
- "host":"example.com"
- }
- }
- GET http://{{host}}:8090/persons/all/
Template | Usage |
---|---|
gtr | GET Request |
gtrp | GET Request with query parameters |
ptr | POST Request with simple body |
ptrp | Post Request with parameter-like body |
mptr | Post Request to submit a form |
fptr | Post Request to submit a form with a file |
- GET https://www.vojtechruzicka.com/
-
- > {%
- client.test("Request executed successfully", function() {
- client.assert(response.status === 200, "Response status is not 200");
- });
- %}
-
- GET https://www.vojtechruzicka.com/
-
- > {%
- client.test("Request executed successfully", function() {
- client.log("Look, I can log!");
- client.assert(response.status === 200, "Response status is not 200");
- client.assert(response.contentType.charset === "UTF-8", "Unexpected content type - charset");
- client.assert(response.contentType.mimeType === "text/html", "Unexpected content type - MIME type");
- client.assert(response.headers.valueOf("x-frame-options") === "DENY", "Frame options not set to DENY");
- client.assert(response.body.indexOf("Vojtech") !== -1, "Expected body to contain 'Vojtech'");
- });
- %}
-
- GET https://www.example.com/auth
- Content-Type: application/json
-
- {
- "token": "secret-token"
- }
-
- > {%
- client.global.set("token", response.body.json.token);
- %}
-
- GET https://www.example.com/foo
- Authorization: Bearer {{token}}
-
Endpoints → Mappings
Since version 2019.2, you can easily convert your existing cURL requests to the format supported by IntelliJ IDEA. All you need to do is to paste a cURL reuest like this to the editor of Intellij's HTTP client:
curl -X POST http://www.example.com/login/ -d 'username=joe&password=1234'
It will be automatically converted to the format supported by IDEA:
- POST http://www.example.com/login/
- Content-Type: application/x-www-form-urlencoded
-
- username=joe&password=1234
Pretty cool, right? Alternatively you can go through the menu:
Tools → HTTP Client → Convert cURL to HTTP Request
In case you need HTTP proxy for your calls, both clients share proxy settings of the whole IDE, which can be configured under Appearance & Behavior → System Settings → HTTP Proxy.
What's cool is that IDEA automatically stores the history of all the requests you performed (up to 50 items). It is available from Tools → HTTP Client → Show HTTP Requests history. What it actually does is that it opens a file called http-requests-log.http in .idea/httpRequests folder. It can look something like this:
- POST http://localhost:8090/persons/add
- Content-Type: application/json
- < C:/_MY/rest-demo/person.json
- <> 2018-01-11T032255.200.txt
- GET http://localhost:8090/persons/all
- <> 2018-01-11T115612.200.json