Original address: Liang Guizhao’s blog

Blog: blog.720ui.com

In the daily development process, we are more or less involved in the API interface testing. For example, some people use the Postman plugin in Chrome or restClient in Firefox. In fact, these tools are one of the most effective ways to test apis, and I’ve been using Postman for API testing. Today, I recommend another handy gadget to help readers quickly test the API. This tool is the Editor REST Client for IDEA.

IDEA’s Editor REST Client has been supported since IntelliJ IDEA 2017.3, and many features were added in 2018.1. In fact, it is an HTTP Client plug-in for IntelliJ IDEA.

Start to work

First, we can create an xxx. HTTP file in any directory. , as shown in the figure.

Here, the three ### are splitting the HTTP request. In fact, a file can contain more than one HTTP request, with ### followed by comments, as shown in the following example.

### User loginPOST http://localhost:8088/oauth/token? grant_type=password&username=lgz&password=123456 Accept : application/json Content-Type : application/json; charset=UTF-8 Authorization: Basic client secret Cache-Control : no-cacheCopy the code

Therefore, we get the response content.

Multi-environment configuration

In the development process, we usually have multiple sets of environments, such as development environment, * test environment, pre-release environment, production environment, etc. Therefore, it would be great if the Editor REST Client could be as multi-environment configured as Postman. In fact, the Editor REST Client already supports this feature by creating a rest-client.env.json file and configuring multiple environments.

{
  "development" : {
    "url" : "http://localhost:8088"."token" : "Bearer 4d74c7fb-0ef4-45ec-b3ff-902eaa3d116c"
  },
  "test" : {
    "url" : "http://localhost:8089"."token" : "Bearer 4d74c7fb-0ef4-45ec-b3ff-902eaa3d116c"
  },
  "preproduction" : {
    "url" : "http://activity.720ui.com"."token" : "Bearer 4d74c7fb-0ef4-45ec-b3ff-902eaa3d116c"
  },
  "product" : {
    "url" : "http://activity.720ui.com"."token" : "Bearer 4d74c7fb-0ef4-45ec-b3ff-902eaa3d116c"}}Copy the code

At this point, change the previous URL, change http://localhost:8088 to {{URL}} instead.

POST {{url}}/oauth/token? grant_type=password&username=lgz&password=123456Copy the code

Here, we get the overall effect.

Case,

Now, let’s write a complete case. For details, see REST Client

### Create user informationPOST {{url}}/v1/m/users Accept : application/json Content-Type : application/json; charset=UTF-8 Authorization: {{token}} {"username": "xiaoyue"."realname": "Small yue"."password": "111111"."email": "[email protected]"."tel": "18305930000"."weixin": "LiangGzone"."sex": 1}### Modify user informationPUT {{url}}/v1/m/users/723181 Accept : application/json Content-Type : application/json; charset=UTF-8 Authorization: {{token}} CachePATCH-Control : no-cache {"username": "xiaoyue"
}

### Query user informationGET {{url}}/v1/c/users/lgz/username Accept : application/json Content-Type : application/json; charset=UTF-8 Authorization: {{token}}### Query the user information listGET {{url}}/v1/c/users? Keyword = beam Accept: application/json content-type: application/json; charset=UTF-8 Authorization: {{token}}Copy the code

The resources

  • Marketplace.visualstudio.com/items?itemN…

(If reproduced, please indicate author and source.)

More wonderful articles, all in the “server thinking” wechat public account!

I invite you to join me on my planet, a group of cohorters, to grow together, and a year from now, to look back at who you once were.