Capture Block Syntax
Wrap capture definitions in>>>capture and <<< markers:
items.#(name=="Jane Doe").id). A trailing # comment is allowed. A line that is not <name> from <source> is a parse error, and a capture block must be closed with <<<.
Capture Sources
hitspec can capture values from these parts of the response:Body Captures
Use dot notation and array indexing to reach into the JSON response:.# for array length and queries:
Assertions and captures share one path normalizer, so the same paths work in
expect body.<path> assertions: you can assert on body.items.# (array length)
directly too. Bracket notation works in both (body.items[0].name,
body[2].id, body.items[*].id).application/json, or any +json type such as
application/problem+json, with or without ; charset=...). On a non-JSON
response only the whole body can be captured.
Captures that find nothing
A capture whose path matches nothing (a typo, an error response with a different shape, a missing header) is left out and reported on stderr, once per run:{{variable}} in another request. A capture whose path contains spaces outside
(...) (a note glued to the path instead of after #) is flagged by
hitspec validate because it can never match.
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.
How values are inserted
A captured value is inserted into the next request exactly as the response had it:- Strings are inserted as-is.
- Numbers keep their exact JSON digits, so
1000000stays1000000and123456789012is not rounded or written as1e+06. - Booleans are
trueorfalse, andnullisnull. - Objects and arrays are inserted as compact JSON, for example
{"id":1,"tags":["x","y"]}.
{{HOME}} or {{$env(SECRET)}}, that text is sent literally and never expanded.