WebStorm 2023.3 Help

HTTP Client reference

The client object holds the HTTP Client session metadata (such as the list of global variables) and lets you test the HTTP response and log text in the output. The HTTP Client session is started when WebStorm starts, and ends when WebStorm is closed. Values are not preserved between WebStorm restarts.

The client object provides access to the global nested object that serves as a variable storage.

Methods

test

Creates a test with the name testName and body func. All tests are executed after the response handler script. Test results are displayed in the Tests tab of the Services tool window.

Parameter

Type

Description

testName

String

Test name

func

function

JavaScript function to test an HTTP response

assert

Checks that the specified condition is true; throws an exception otherwise. The optional message parameter serves as an exception message.

Parameter

Type

Description

condition

boolean

The condition to check in the response

message

String

The optional message to return in case the condition evaluates to false.

log

Prints text to the output of the response handler or pre-request script and then terminates the line.

Parameter

Type

Description

text

String

Text to be printed in the output of the response handler or pre-request script.

exit

Terminates execution of the response handler script.

Properties

global

The global variables storage, which is used for setting, retrieving, or removing variables.

Once you assign a value to a global variable (client.global.set(VariableName, VariableValue)), you can access it as {{VariableName}} in subsequent HTTP requests or using client.global.get("VariableName") in response handler scripts and pre-request scripts. See Use global variables for a more detailed example.

Global variable methods

The global object serves as a variable storage and is used for setting, retrieving, or removing variables. These variables are global because, once set, they can be accessed from any HTTP request.

set

Saves the variable with the varName name to the storage and sets its value to varValue. See Use global variables for a more detailed example.

Parameter

Type

Description

varName

String

The name of the variable to be saved to the global storage.

varValue

String

The variable value to be saved to the global storage.

get

Returns the value of the varName variable.

Parameter

Type

Description

varName

String

The name of the variable to be returned.

isEmpty

Checks whether the global object has no variables defined.

clear

Removes the varName variable from the variables storage.

Parameter

Type

Description

varName

String

The name of the variable to be removed.

clearAll

Removes all variables from the variables storage.

Last modified: 07 November 2023