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:
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:
Supported methods
|
|
---|---|
Supported properties
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: