Skip to main content
Assertions let you validate every aspect of an HTTP response — status codes, headers, body content, response times, and more. hitspec provides 26 operators grouped into six categories.

Assertion Block Syntax

Wrap assertions in >>> and <<< markers:
Each line inside the block follows this pattern:
When the operator is ==, you can omit it:

Assertion Subjects


Equality and Comparison

Compare values using standard comparison operators.
Use expect status 200 as shorthand for expect status == 200. The == operator is implied when omitted.

String Operators

Match, search, and compare string values.
Regular expressions in matches are enclosed in forward slashes: /pattern/. The pattern uses Go’s regexp syntax.

Existence and Type

Check whether values exist and validate their types. Supported types for the type operator: null, boolean, number, string, array, object.

Length and Arrays

Validate array lengths and check array contents.

The each Operator

each applies an assertion to every element in an array. It is useful for validating the shape of list responses:

The in Operator

in checks whether a value is a member of a set. List values in square brackets:

The includes Operator

includes checks whether an array contains a specific value:

Schema Validation

Validate the entire response body against a JSON Schema file.
Where schemas/user.json contains a standard JSON Schema:
Schema file paths are resolved relative to the .http file that references them.

Snapshot Testing

Compare the response body against a previously saved baseline. On first run, the snapshot is created. On subsequent runs, the response is compared against it.
Snapshots are stored in a __snapshots__ directory next to your test file. Update them when the response intentionally changes:
Snapshot testing works well for responses that should remain stable over time, such as configuration endpoints or reference data.

Combining Assertions

A single assertion block can mix operators from any category:

Header Assertions

Assert on response headers using the header <name> subject:

Testing Error Responses

Assertions are equally useful for verifying error behavior:
Last modified on February 10, 2026