HTTP Client Enhancements

We continue improving the editor-based HTTP client, and PhpStorm 2018.2 brings several useful enhancements to it: you can now use environment variables inside the request body, apply code formatting to POST request bodies, and enjoy built-in Unicode support.

Let’s take a closer look at these new features.

Support for environment variables in the request body

Environment variables let you parameterize certain parts of your request and substitute them with actual values when a request is executed. Previously, you could use variables for specifying the request’s host, port, and path, query parameter or value, and header value.

In PhpStorm 2018.2, you can use variables for providing arbitrary values within the POST request body, too.

The idea remains the same: declare your variables in an env file, and use the variables’ placeholders enclosed between double curly braces either directly inside an HTTP file or in the external files that you’ve included as the request body.

When you execute the request, PhpStorm will prompt you to choose the environment holding the desired variable’s value:

vars_in_body

Formatting of POST request body

Another improvement you’ll notice when working with POST requests in PhpStorm 2018.2 is the ability to format the request’s body.

To use it, simply invoke the Code | Reformat code action.

POST Body reformat

The request’s body will be formatted in accordance with its Content-Type ; if necessary, you can customize the code style for the corresponding language (for example, JSON or XML) under Preferences | Editor | Code Style.

Please note that formatting HTTP requests that contain variables in the request body is currently not supported. To format such a request, press Alt+Enter and choose Edit JSON/XML fragment. The fragment will open in a separate editor tab, from where you can format is as usual:

POST Body reformat

Decoding Unicode entities and character escapes in JSON replies

PhpStorm 2018.2. introduces the long-awaited support for Unicode symbols and character escape sequences in the HTTP response body.

rest_encoding-2

With this support in place, you can inspect your responses in a natural manner, without looking into the characters table to find out what these magical letters actually translate to.

Your JetBrains PhpStorm Team
The Drive to Develop

This entry was posted in Cool Feature and tagged , . Bookmark the permalink.
  • http://aqeeliz.com/ aqeeliz

    Is there any way to send url params in a POST request?

    For a POST request with URL like {{host}}/something.json?one=param&two=param
    this only sends {{host}}/something.json

  • Boris Lednár

    Great stuff! Finally I can chain my requests and pass results to another requests :)

    It would be great if you could name requests since now it creates configurations by request number (position in file), for example “request #20”, but if I add/delete some requests before this, my saved configuration needs to be updated

    • Eugene Morozov

      All three are valid feature requests, I haven’t found a single duplicate.
      Could you please file them?
      https://youtrack.jetbrains.com/newIssue?project=WI

      • Boris Lednár

        cool, I will do that soon :)

        One more question: I was thinking about learning and trying to do some plugins, is there any documentation/article/hint/tips about extending HTTP client? Let’s say I would like to add possibility to set variables at the start of the request collection file, which could be used similar to env variables (maybe there is already some plugin/issue for that, this is just hypothetical :)), is there any docs/source code I can check to see what’s possible?

        Thanks!