### Test JSONPlaceholder APIGET https://jsonplaceholder.typicode.com/users/1Accept: application/json//# status == 200//# body contains "Leanne Graham"//# body contains "hildegard.org"//# header["content-type"] contains "json"
The contains operator is case-sensitive for body content but case-insensitive for headers.
### Ensure no sensitive data leakedGET https://api.example.com/public/profile//# body not_contains "password"//# body not_contains "secret"//# body not_contains "token"//# header["content-type"] not_contains "xml"
### Test response formatGET https://api.example.com/data//# status starts_with "2"//# body starts_with "{\"data\""//# header["content-type"] starts_with "application"
### Test with regex patternsGET https://api.example.com/users/123Accept: application/json//# status matches_regex "^2.*"//# body matches_regex ".*success.*"//# header["content-type"] matches_regex "application/.*"
### Ensure no error codesGET https://api.example.com/status//# status not_matches_regex "^[45].*"//# body not_matches_regex ".*error.*"//# body not_matches_regex ".*exception.*"
Combine different assertion types for comprehensive validation:
### Comprehensive API testGET https://jsonplaceholder.typicode.com/users/1Accept: application/json//# status == 200//# status starts_with "2"//# status not_matches_regex "^[45].*"//# header["content-type"] contains "json"//# header["content-type"] == "application/json; charset=utf-8"//# body contains "Leanne Graham"//# body contains "hildegard.org"//# body not_contains "error"//# body matches_regex ".*\"id\"\\s*:\\s*1.*"
All assertions must pass for the test to succeed. If any assertion fails, the entire request is marked as failed.
### Test JSON structureGET https://api.example.com/users/1Accept: application/json//# status == 200//# body contains "\"id\""//# body contains "\"email\""//# body contains "\"name\""//# body matches_regex ".*\"id\"\\s*:\\s*[0-9]+.*"//# body not_contains "password"
### Test error response formatGET https://api.example.com/users/999999//# status == 404//# body contains "error"//# body contains "not found"//# body matches_regex ".*\"message\".*"
Here’s a comprehensive test demonstrating multiple assertion types:
### Test with some failing assertions (to show diagnostics)GET https://httpbin.org/json//# status == 404//# body contains "nonexistent"//# header["content-type"] == "text/plain"
When this test runs, HTTPSpec will report all failures:
✗ Test with some failing assertions (120ms) [Fail] Expected status 404, got 200 [Fail] Expected body to contain "nonexistent", got "{...}" [Fail] Expected header "content-type" to be "text/plain", got "application/json" 3 assertions failed
HTTPSpec reports all assertion failures, not just the first one. This helps you understand all issues at once.
//# status == 200//# status != 404//# status contains "20" # Status contains substring//# status starts_with "2" # 2xx status codes//# status matches_regex "^2.*" # 2xx using regex
Response Body
//# body == "exact match"//# body contains "substring"//# body not_contains "error"//# body starts_with "{"//# body ends_with "}"//# body matches_regex ".*pattern.*"