IntelliJ IDEA 2018.2 Help

Testing RESTful Web Services


Testing RESTful Web Services is supported via the HTTP Client bundled plugin, which is by default enabled. If not, activate it in the Plugins settings page of the Settings dialog box.

There are two main use cases when you need to compose and run requests to a RESTful Web service:

  • When you have developed and deployed a RESTful Web service and want to make sure it works as expected: that it is accessible in compliance with the specification and that it responds correctly.

  • When you are developing an application that addresses a RESTful Web service. In this case it is helpful to investigate the access to the service and the required input data before you start the development. During the development, you may also call the Web service from outside your application. This may help locate errors when your application results in unexpected output while no logical errors are detected in your code and you suspect that the bottleneck is the interaction with the Web service.

Testing a RESTful Web service includes the following checks:

  • That URL addresses are constituted correctly based on the service deployment end-point and the method annotations.

  • That the generated server requests call the corresponding methods.

  • That the methods return acceptable data.

IntelliJ IDEA enables you to run these checks from the REST Client tool window by composing and submitting requests to a server, viewing and analyzing server responses.

If necessary, configure the Proxy settings on the HTTP Proxy page of the Settings dialog box.

Composing and submitting a test request to a Web service method

  1. If you are going to test your own Web service, make sure it is deployed and running.

  2. Choose Tools | HTTP Client | Test RESTful Web Service. The REST Client dedicated tool window opens.

  3. To have IntelliJ IDEA generate an authentication header which will be used in basic authentication, click the Generate Authorization Header button and in the dialog box that opens, specify your user name and password for accessing the target RESTful Web service through. Based on these credentials IntelliJ IDEA will generate an authentication header which will be used in basic authentication. Learn more at

  4. Select the test request method from the HTTP method drop-down list. The available options are:
  5. Provide the data to calculate the URL address of the target method:
    1. In the Host/port text box, type the URL address of the host where the Web service is deployed.

    2. From the Path drop-down list, choose the @path annotation that corresponds to the method the call to which you need to test.

    You can enter the entire URL address of a method to test in the Host/port text box. Regardless of the chosen HTTP method, upon pressing icons toolwindows toolWindowRun svg IntelliJ IDEA will split the URL address into the host/port and the path to the method. The extracted relative path will be shown in the Path text box and the extracted parameters will be added to the list in the Request Parameters pane of the Request tab.

  6. Create a set of parameters to be passed to the target method and specify their values. Depending on the chosen request method, you can create a list of parameters in two ways:
    • For GET requests, specify the parameters to be passed as a query string inside the URL. Use the Request Parameters pane. By default, the pane shows an empty list with one line.
      • To add a parameter, click Add icons general add svg, then specify the name of the parameter in the Name text box and the value of the parameter in the Value drop-down list.

      • To delete a parameter from the list, select it and click Remove icons general remove svg.

      • To suppress sending the specified query string parameters and disable the controls in the Request Parameters pane, press the Don't send anything toggle button icons actions clear.

    • To have the parameters passed to the target method inside a request message body, use the Request Body pane or have them inserted in the request from a local file. The Request Body pane is disabled when the GET, DELETE, HEAD, or OPTIONS request method is selected.
      • To specify the parameters explicitly, choose the Text option and type the parameters and values in the text box.

      • To have the parameters inserted from a text file, choose the File contents option and specify the file location in the File to send field.

      • To have a binary file converted and sent in the request, choose the File upload(multipart/form-data) option and specify the file location in the File to send field.

    In either case, the set of parameters and their types should comply with the Web service API, in particular, they should be exactly the same as the input parameters of the target method.
  7. To submit a request to the server, click the Submit request button icons toolwindows toolWindowRun svg.

    Note that the server may lack certificate, or be untrusted.

Viewing and analyzing responses from Web services

  1. To view the response to the server request, switch to the Response tab. The tab is opened automatically when a response is received. By default, the server response is shown in the format, specified in the request header through the content-type field.

  2. To have the response converted into another format and opened in a separate tab in the editor, use the View as HTML icons fileTypes html, View as XML ps iconFileTypeXML, View as JSON viewAsJSON buttons.

  3. To view the technical data provided in the header of a Web service response, switch to the Response Headers tab.

Working with cookies

Using the dedicated Cookies tab, you can create, save, edit, and remove cookies, both received through responses and created manually. The name and value of a cookie is automatically included in each request to the URL address that matches the domain and path specified for the cookie, provided that the expiry date has not been reached.

The tab shows a list of all currently available cookies that you received through responses or created manually. The cookies are shown in the order they were added to the list. When you click a cookie, its details become editable and are displayed in text boxes. See REST Client Tool Window for details.

  • No specific steps are required to save a cookie received through a response, all the cookies received from servers are saved automatically. To edit a received cookie, click the row with the cookie in the list and update the details that are now shown in editable text boxes.

  • To create a cookie manually, click icons general add svg and specify the following:
    • The name and value of the cookie to be included in requests.

    • The domain and path the requests to which must be supplied with the name, value, and expiry date of the cookie.

  • To remove a cookie from the list, select the row with the cookie and click icons general remove svg.

Configuring Proxy settings

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), choose System Settings under Appearance & Behavior, then choose HTTP Proxy.

  2. In the Proxy dialog that opens, select Manual proxy configuration and specify the following:
    • Enter the proxy host name and port number in the Host name and Port number fields.

    • To enable authorization, select the Proxy authentication checkbox and type the user name and password in the corresponding fields.

Reusing requests

During a IntelliJ IDEA session, IntelliJ IDEA keeps track or requests and you can run any previously executed request. You can also save the settings of a request in an XML file so they are available in another IntelliJ IDEA session. When necessary, you can retrieve the saved settings and run the request again.

Rerunning a request within a IntelliJ IDEA session

  1. Click the Replay Recent Requests button icons actions back.

  2. From the Recent Requests pop-up list, select the relevant request. The fields are filled in with the settings of the selected request.

  3. Click the Submit Request button icons toolwindows toolWindowRun svg.

Saving the settings of a request so they can be retrieved in another IntelliJ IDEA session

  • Click the Export Request button icons toolbarDecorator export svg. In the dialog box that opens, specify the name of the file to save the settings in and its parent folder.

Running a request saved during a previous IntelliJ IDEA session

  1. Click the Import Request button importFromXML.

  2. In the dialog box that opens, select the relevant XML file. The fields are filled in with the settings of the selected request.

  3. Click the Submit Request button icons toolwindows toolWindowRun svg.

Last modified: 20 November 2018

See Also