PhpStorm 2025.1 Help

JavaScript API supported by HTTP Client

console.log

The HTTP Client supports the console.log() method to print the text value (or multiple values separated by commas) to the output of the response handler or pre-request handler scripts. You can also use client.log for the same purpose. Example:

GET example.org > {% console.log(response.status) %}

You can also pass a JavaScript object (for example, console.log(response.body)), and it will be displayed in the output in JSON format with proper syntax highlighting.

DOM methods and properties

The HTTP Client supports some of the DOM tree methods and properties that allow you to parse and manipulate XML and HTML documents received as part of the response body (or created using DOMParser). Supported methods include:

getElementsByTagName()

Returns a collection of elements with the given tag name. For example:

GET https://examples.http-client.intellij.net/xml > {% const slide = response.body.getElementsByTagName("slide")[0] console.log(slide) %}
getElementsByName()

Returns a collection of nodes with a given name attribute. For example:

getElementById()

Retrieves an Element object by its id.

getElementsByClassName()

Returns an array-like object of all child elements with the given class name.

DOMParser

Parse XML or HTML source code from a string into a DOM Document using the parseFromString() method. For example:

GET example.org > {% const xmlStr = '<q id="a"><span class="test" id="b">hey!</span><span id="bar">world</span><foo class="test" id="x-foo"/><bar name="x-foo"/></q>'; const doc = new DOMParser().parseFromString(xmlStr, "application/xml"); console.log(doc.getElementById("a")) console.log(doc.getElementById("b")) console.log(doc.getElementsByClassName("test")) console.log(doc.getElementsByTagName("span")) console.log(doc.getElementsByName("x-foo")) %}
createElement(tagName)

Creates the HTML element specified by tagName.

GET example.org > {% const xmlStr = '<q id="a"><span class="test" id="b">hey!</span><span id="bar">world</span><foo class="test" id="x-foo"/><bar name="x-foo"/></q>'; const doc = new DOMParser().parseFromString(xmlStr, "application/xml"); const bodyElement = doc.createElement("body"); %}

Start typing a method name to get completion for supported methods. Hover over it to get quick documentation. To view all supported DOM methods and properties, expand the sections below:

URLSearchParams

URLSearchParams is a JavaScript object that makes it easy to work with the query string part of a URL. URLSearchParams accepts parameters in the following formats:

  • Query string: URLSearchParams("key=value&key2=value2");

  • Key-value pairs representing URL parameters: URLSearchParams({ key1: "value1", key2: "value2" })

  • Array of key-value pairs: URLSearchParams([["key1", "value1"], ["key2", "value2"]])

The HTTP Client supports all known URLSearchParams methods. Example:

< {% client.global.set('query', 'foo=1&bar=2') const params = new URLSearchParams(client.global.get('query')); const params2 = new URLSearchParams([["planet", "tatooine"], ["year", "2"]]); const params3 = new URLSearchParams({key1: "value1", key2: "value2"}); console.log(params.has("bar")); // outputs true console.log(params.has("param")); // outputs false params.append("foo", 3); console.log(params.getAll("foo")); // outputs ["1","3"] for (let value of params.values()) { console.log(value); // outputs 1 2 3 } for (let key of params2.keys()) { console.log(key); // outputs planet year } client.global.set("query",params.toString()) %} GET example.org/{{query}}

Base64 encoding: btoa and atob

The HTTP Client supports the btoa() and atob() methods.

  • Use Window.btoa(stringToEncode) to create a Base64-encoded ASCII string from a stringToEncode string.

  • Use Window.atob(encodedData) to decode a string of data which has been encoded using Base64 encoding.

For example:

GET https://examples.http-client.intellij.net/ip > {% const encodedData = Window.btoa("Hello, world"); // encode a string const decodedData = Window.atob(encodedData); // decode the string console.log(decodedData); // prints "Hello, world" %}

Execute shell commands

To let you interact with the operating system by running shell commands, the HTTP Client supports the following methods:

exec(command[, options][, callback])

Spawns a shell and then executes the command within that shell, buffering any generated output.

execFile(file[, args][, options][, callback])

Similar to exec() except that it does not spawn a shell by default.

execSync(command[, options])

Identical to exec() with the exception that the method will not return until the child process has fully closed.

execFileSync(file[, args][, options])

identical to execFile() with the exception that the method will not return until the child process has fully closed.

spawn(command[, args][, options])

Spawns a shell, then executes the command within that shell, buffering any generated output.

spawnSync(command[, args][, options])

Identical to spawn() with the exception that the function will not return until the child process has fully closed.

The supported options include:

cwd

Specifies the directory in which the command should be executed.

env

Specifies a set of environment variables that should be available to the process.

timeout

Maximum duration (in milliseconds) the process is allowed to run.

maxBuffer

Sets a maximum limit (in characters) for the size of the output.

shell

Specifies the shell to execute the command with.

signal

Specifies the signal to be sent to the process when it needs to be terminated

callback

Not an option, but a separate parameter, which can be passed to the asynchronous methods. The callback is a function that will be called when the process terminates.

For example:

### List all directories in the specified folder GET https://examples.http-client.intellij.net > {% const result = execSync("ls -l", { cwd: '/Users/John.Doe/Docs/' }) console.log(`result: ${result}`) %} ### Pass an environment variable to the process < {% const result = execSync('bash -c "set"', { env : { name: 'John' }}) console.log(`result: ${result}`) %} GET https://examples.http-client.intellij.net
Last modified: 27 February 2025