Assertions
Assertions define what a healthy response looks like. APIAssert supports multiple assertion types and operators.
Supported Types
status_coderesponse_timeheaderjson_pathbodyregexexists
Supported Operators
equalsnot_equalscontainsnot_containsgreater_thanless_thanmatchesexists
Type Notes
Status Code
Use for exact status checks (200, 201, etc.) or non-equality checks.
Response Time
Compares request latency in milliseconds.
Header
Checks headers case-insensitively by header name.
JSON Path
Supports dot and bracket notation, for example:
$.data.user.iditems[0].status
Regex
Runs pattern matching against full response body.
Exists
Use either:
header:Content-Typefor header existence- A JSON path (
$.data.id) for payload existence
Example Rules
| Type | Operator | Property | Value |
|---|---|---|---|
status_code |
equals |
- | 200 |
response_time |
less_than |
- | 500 |
header |
contains |
content-type |
application/json |
json_path |
equals |
$.data.active |
true |
exists |
exists |
$.data.id |
- |
Best Practices
- Keep one fast status assertion at minimum.
- Add JSON path assertions for business-critical fields.
- Set response-time thresholds based on production SLOs.
- Prefer small, explicit assertions over one large regex.