Complete reference for all HTTPSpec assertion types and operators
Assertions in HTTPSpec validate HTTP responses against expected values. This guide covers all supported assertion types, operators, and provides examples for each.
### Status is not 404GET https://api.example.com/users//# status != 404### Body doesn't match error messageGET https://api.example.com/users/123//# body != "User not found"### Header is not XMLGET https://api.example.com/api//# header["content-type"] != "application/xml"
Checks if the value starts with a specific string:
### Status starts with "2" (2xx success codes)GET https://api.example.com/users//# status starts_with "2"### Body starts with expected prefixGET https://api.example.com/greeting//# body starts_with "Hello"### Header starts with "application"GET https://api.example.com/api//# header["content-type"] starts_with "application"
### Body ends with expected suffixGET https://api.example.com/message//# body ends_with "world!"### Header ends with charsetGET https://api.example.com/api//# header["content-type"] ends_with "charset=utf-8"
Verifies the value does NOT match a regex pattern:
### Status doesn't match error codes (4xx, 5xx)GET https://api.example.com/users//# status not_matches_regex "^[45].*"### Body doesn't match error patternPOST https://api.example.com/submit//# body not_matches_regex ".*error.*"//# body not_matches_regex ".*failed.*"
### Success responseGET https://api.example.com/users//# status == 200### Created responsePOST https://api.example.com/usersContent-Type: application/json{"name": "Alice"}//# status == 201### Not foundGET https://api.example.com/users/999999//# status == 404### Any 2xx success codeGET https://api.example.com/resource//# status starts_with "2"### Not an errorGET https://api.example.com/users//# status != 500//# status not_matches_regex "^[45].*"
### Exact body matchGET https://api.example.com/health//# body == "OK"### Contains expected dataGET https://api.example.com/users/123//# body contains "John Doe"//# body contains "john@example.com"//# body contains "\"id\":123"### Multiple contains checks for JSON fieldsGET https://api.example.com/users/123//# body contains "name"//# body contains "email"//# body contains "created_at"### Doesn't contain error messagesPOST https://api.example.com/usersContent-Type: application/json{"name": "Alice"}//# status == 201//# body not_contains "error"//# body not_contains "failed"//# body contains "Alice"### Regex pattern matchingGET https://api.example.com/users/123//# body matches_regex ".*@example\\.com.*"//# body not_matches_regex ".*error.*"
Combine multiple assertion types for comprehensive validation:
### Create user with full validationPOST https://api.example.com/usersContent-Type: application/jsonAuthorization: Bearer ABC123{ "name": "Alice Smith", "email": "alice@example.com"}//# status == 201//# header["content-type"] == "application/json"//# header["location"] starts_with "/users/"//# body contains "Alice Smith"//# body contains "alice@example.com"//# body contains "id"//# body not_contains "error"
# Validate email format in response//# body matches_regex "[a-z0-9]+@[a-z0-9]+\\.[a-z]+"# Validate UUID format//# body matches_regex "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}"
Body and status assertions are case-sensitive, but header name matching is case-insensitive:
# These are equivalent for headers//# header["content-type"] == "application/json"//# header["Content-Type"] == "application/json"# But body matching is case-sensitive//# body contains "Alice" # Won't match "alice"