Home » Software Development » IntelliJ’s text based HTTP client

About Michael Scharhag

Michael Scharhag
Michael Scharhag is a Java Developer, Blogger and technology enthusiast. Particularly interested in Java related technologies including Java EE, Spring, Groovy and Grails.

IntelliJ’s text based HTTP client

IntelliJ provides a HTTP client that is purely text based. While this might sound strange at the beginning it turns out that this is a very useful feature.

Getting started

First we need to create a file whose name ends with .http or .rest. For example: my-requests.http.

To issue a simple GET request we have to write down the request in our newly created file.

For example:

1
GET http://localhost:8080/products

IntelliJ now adds a small Run-Icon next to the line which allows you to execute the request.

If we want to POST a piece of JSON, we simply have to add a Content-Type header and the request body:

1
2
3
4
5
6
7
POST http://localhost:8080/products
Content-Type: application/json
 
{
  "name""My other Product",
  "description""hu?"
}

Please note that there has to be a blank line between headers and request body.

Of course IntelliJ has syntax highlighting and auto completion for writing down headers and JSON:

Multiple requests in the same file need to be separated with ###. For example:

01
02
03
04
05
06
07
08
09
10
11
GET http://localhost:8080/products
 
###
 
POST http://localhost:8080/products
Content-Type: application/json
 
{
  "name""My other Product",
  "description""hu?"
}

Using variables

With {{ .. }} we can add variables to our requests. Maybe we want to issue the same request against different environments. To support this, we can update our request with a host variable:

1
GET http://{{host}}/products

Next we need to define the {{host}} variable. For this we create a http-client.env.json file and add the following content:

1
2
3
4
5
6
7
8
{
  "development": {
    "host""http://localhost:8080"
  },
  "production": {
    "host""http://my-cool-api.com"
  }
}

This defines two environments: development and production. Both environments define the host variable with a different value.

When running the request, we can now choose the environment we want:

Share requests with your team

The simple text-based request definition allows easy sharing with your team. You can even check in request files into your version control system. Of course you do not want to check in passwords or API keys that might be needed for request execution. IntelliJ supports this with a separate private environment file (http-client.private.env.json). Like in the previous environment example, we can use this file to define variables.

For example:

1
2
3
4
5
{
  "dev": {
    "api-key""S3CR3T"
  }
}

To make sure no secrets are checked in, we can explicitly exclude this file from our version control system.

Published on Java Code Geeks with permission by Michael Scharhag, partner at our JCG program. See the original article here: IntelliJ’s text based HTTP client

Opinions expressed by Java Code Geeks contributors are their own.

(+1 rating, 1 votes)
You need to be a registered member to rate this.
3 Comments Views Tweet it!
Do you want to know how to develop your skillset to become a Java Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. JPA Mini Book
2. JVM Troubleshooting Guide
3. JUnit Tutorial for Unit Testing
4. Java Annotations Tutorial
5. Java Interview Questions
6. Spring Interview Questions
7. Android UI Design
and many more ....
I agree to the Terms and Privacy Policy
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Nick Christopher
nwillc
1 month ago

Is this feature still a limited version in the community vs the commercial version? I seem to remember it was.

Vijay
Vijay
1 month ago
Reply to  nwillc

It’s only in ultimate version

Prasad
Prasad
29 days ago

What is best plugin Rest Client Plugin for Intelij Community editon.