PyCharm 2025.1 Help

HTTP Client reference

The client object provides access to the HTTP Client session metadata and lets you test the HTTP response and log text in the output. The object is reinitialized every time PyCharm starts, without preserving data between PyCharm restarts.

The client object also exposes the nested global 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 and removing global variables and headers.

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 variables and headers

The global object allows you to do the following:

  • Set and get global variables.

  • Set global headers.

    Global headers help you avoid repeated initialization of the same headers across multiple HTTP requests. Once set, they are implicitly applied to all subsequent requests within the same execution flow.

    Global headers are not intended to store persistent state. They are limited to a single execution flow and are designed to simplify header reuse.

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.

headers.set

Use client.global.headers.set(headerName, headerValue) to add the headerName header with the headerValue. For example:

client.global.headers.set("X-Our-Header-1", "value1")

When used in response handler scripts, the header is applied to all subsequent HTTP requests. When used in pre-request scripts, the header is applied to the current HTTP request and to all subsequent requests.

Parameter

Type

Description

headerName

String

The name of the header to be used in HTTP requests.

headerValue

String

The header value.

To remove the header, use null as the value:

client.global.headers.clear(headerName, null))
Last modified: 25 June 2025