Skip to main content
The script editor includes a library of ready-to-use code snippets for common scripting tasks - writing tests, reading and setting variables, and logging request or response details. Instead of typing these patterns from scratch, you can browse, search, and insert them with a single click.

Opening the snippets panel

In any pre-request or post-response script editor, click the Snippets button in the toolbar above the editor. A panel opens with a search box at the top and a categorized list of snippets below.
Snippets popover open in the post-response script editor showing categorized code snippets including Tests and Response body checks
The snippets shown adapt to the active script phase. For example, response assertions only appear when you are editing a post-response script - they are hidden in the pre-request editor where rq.response is not available.

Searching for a snippet

Type in the search box to filter snippets by name. The list narrows to matches as you type. Clear the search to return to the full list.

Inserting a snippet

Click any snippet name to insert its code at the current cursor position in the editor. The panel stays open so you can insert multiple snippets in one session.

Available snippets

Tests

These snippets are available in post-response scripts only.

Status code

Response body

Example - JSON schema validation:

Response headers

Response time


Variables

These snippets are available in both pre-request and post-response scripts.

Get a variable

Set a variable

A common pattern is to extract a token from a response and store it for use in subsequent requests:
For a worked example of chaining two requests where the second depends on data from the first, see Chaining API requests.

Clear a variable


Request / Other

These snippets are available in both phases unless noted. Logs appear in the DevTools console tab, tagged with #script. See DevTools for details.