Skip to main content
Captures extract values from HTTP responses — body fields, headers, status codes, and timing — and store them as variables for use in later requests. This is the foundation for building multi-step test flows like authentication, CRUD operations, and workflow testing.

Capture Block Syntax

Wrap capture definitions in >>>capture and <<< markers:
Each line follows this pattern:

Capture Sources

hitspec can capture values from four parts of the response:

Body Captures

Use dot notation and array indexing to reach into the JSON response:
Body paths use GJSON syntax, so the full GJSON path language is available — including .# for array length and queries:
The same GJSON path syntax works in expect body.<path> assertions, so you can assert on body.items.# (array length) directly too.

Header Captures

Status and Duration Captures

Using Captured Values

Captured values are referenced using the {{requestName.captureName}} pattern. The requestName is the value of the @name directive on the capturing request.
Three things are required for captures to work across requests:
  1. The source request must have a # @name directive.
  2. The source request must have a >>>capture block.
  3. The consuming request must declare # @depends on the source request to guarantee execution order.

Real-World Examples

Authentication Flow

CRUD Workflow

Capturing Headers for Pagination

Captures and Assertions Together

A request can have both assertion and capture blocks. Assertions are evaluated first; if they fail, captures are still performed (allowing dependent requests to attempt execution):
Place assertion blocks before capture blocks for readability. Both blocks belong to the same request — their order does not affect behavior.
Last modified on June 16, 2026