Browse docs
On this page

Assertions

Assertions define what a healthy response looks like. APIAssert supports multiple assertion types and operators.

Supported Types

  • status_code
  • response_time
  • header
  • json_path
  • body
  • regex
  • exists

Supported Operators

  • equals
  • not_equals
  • contains
  • not_contains
  • greater_than
  • less_than
  • matches
  • exists

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.id
  • items[0].status

Regex

Runs pattern matching against full response body.

Exists

Use either:

  • header:Content-Type for 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.

Related