Creating an HTTP request file

You can work with HTTP requests either from scratch files or from physical files of the HTTP Request type:

Scratch files can be used to test HTTP requests during development. A scratch file is not stored inside a project, so IntelliJ IDEA can modify it and add additional information about the request. When an HTTP request is executed from a scratch file, the link to the response output file is added below the request and at the top of the requests history file.

Physical files can be used for documenting, testing and validating HTTP requests. A physical file is stored inside your project, and IntelliJ IDEA will not modify it. When an HTTP request is executed from a physical file, this file is not modified. Information about the executed request with the link to the response output file is added to the top of the requests history file.

To create a new physical HTTP requests file, on the File menu, point to New, and then click HTTP Request.

If Content-Type is not specified, you can inject a language fragment manually. For more information, see Using Language Injections.

Using environment variables

When composing an HTTP request, you can parametrize its elements using environment variables. For example, instead of providing the host name in your request explicitly, you can use the {{host}} placeholder. Then you define a set of environment variables in your project holding the desired host definitions. When executing the request, IntelliJ IDEA will provide a choice of defined environments, in our case, the host to send the request to:

Environment variables are defined in the rest-client.env.json environment files, which must be stored inside the project.

A variable can hold the values for host, port, path, query parameter or value, and header value. The name of the variable can only contain letters, digits, the underscore symbol (_), or the hyphen symbol (-).

The following sample environment file defines two environments: development and production.

Moving an HTTP request

You can use the Move refactoring to move your HTTP requests from scratches to physical files, as well as between physical files.

Select the request to be moved and do one of the following:

On the main menu, or on the context menu, choose Refactor | Move.

Press F6.

In the dialog box that opens, click to select the file or type the full path to the file you want to move the request to. Note that you can specify the name of a non-existing file, in which case a new file with the provided name will be created automatically.

Opening a response

When you execute an HTTP request, IntelliJ IDEA automatically saves the response into a separate file under the .idea/httpRequests/ directory. You can view the 50 most recently stored responses and navigate to the corresponding files using the requests history. If the request was executed from a scratch file, the link to its response output is also added below the original request:

To open a particular response in a new editor tab, do any of the following:

Place the caret at the link to the response you want to open, and choose View | Jump to Source on the main menu, or press Ctrl+B or F4.

Comparing responses

When a request is executed from a scratch file, the link to the response output file is added below the original request. To compare the request execution results in a scratch file, do any of the following:

Place the caret at the link to the response file. Press Alt+Enter and select the Compare with <response name> intention action.

Click the icon in the left gutter and select Compare with <response name> from the pop-up menu:

When a request is executed from a physical file, the link to the response output is added to the requests history. To compare the execution results in the requests history, do the following:

Place the caret at the link to the response file. Choose View | Jump to Source on the main menu, or press Ctrl+B or F4 to open this file in a new editor tab.

Choose View | Compare with... on the main menu, or press Ctrl+D. IntelliJ IDEA will prompt you to open a response file from the httpRequests folder.

Select the response file you would like to compare the current file with and click Open.

The two response files will be opened in the Differences viewer allowing you to compare their contents:

Viewing requests history

IntelliJ IDEA automatically saves the 50 recently executed requests into the http-requests-log.http file, which is stored on the project level under the .idea/httpRequests/ directory. Using the requests history, you can quickly navigate to a particular response as well as re-run any request.

If a request is executed from the requests history, the execution information and the link to the response output will be added to the top of the requests history file.

To open the requests history, click the Show HTTP Requests History button in the top-right corner of the editor or choose Tools | Show HTTP Requests History on the main menu.