Contrast Ratio Validator
API Contract
REST
/api/v1/contrast-ratios
6 endpoints
GET
/api/v1/contrast-ratios/api/v1/contrast-ratios
List all saved contrast ratio check results
Public
Response Example
{
"data": [
{
"id": "cr-001",
"foreground_hex": "#1A1A2E",
"background_hex": "#FFFFFF",
"contrast_ratio": 14.73,
"foreground_luminance": 0.011,
"background_luminance": 1,
"compliant_normal_text": true,
"compliant_large_text": true,
"created_at": "2026-03-26T09:00:00Z"
},
{
"id": "cr-002",
"foreground_hex": "#9E9E9E",
"background_hex": "#FFFFFF",
"contrast_ratio": 3.95,
"foreground_luminance": 0.216,
"background_luminance": 1,
"compliant_normal_text": false,
"compliant_large_text": true,
"created_at": "2026-03-26T09:01:00Z"
}
],
"pagination": {
"page": 1,
"limit": 20,
"total": 2
}
}
GET
/api/v1/contrast-ratios/api/v1/contrast-ratios/:id
Get a specific contrast ratio result by ID
Public
Response Example
{
"id": "cr-001",
"foreground_hex": "#1A1A2E",
"background_hex": "#FFFFFF",
"contrast_ratio": 14.73,
"foreground_luminance": 0.011,
"background_luminance": 1,
"compliant_normal_text": true,
"compliant_large_text": true,
"wcag_level": "AAA",
"created_at": "2026-03-26T09:00:00Z"
}
POST
/api/v1/contrast-ratios/api/v1/contrast-ratios
Calculate and save a contrast ratio check
Public
Request Example
{
"foreground_hex": "#1A1A2E",
"background_hex": "#FFFFFF",
"context": "body-text"
}
Response Example
{
"id": "cr-003",
"foreground_hex": "#1A1A2E",
"background_hex": "#FFFFFF",
"contrast_ratio": 14.73,
"foreground_luminance": 0.011,
"background_luminance": 1,
"compliant_normal_text": true,
"compliant_large_text": true,
"wcag_level": "AAA",
"context": "body-text",
"created_at": "2026-03-26T10:00:00Z"
}
PUT
/api/v1/contrast-ratios/api/v1/contrast-ratios/:id
Update context or metadata on a saved contrast ratio result
Public
Request Example
{
"context": "heading-large",
"foreground_hex": "#1A1A2E",
"background_hex": "#F5F5F5"
}
Response Example
{
"id": "cr-003",
"foreground_hex": "#1A1A2E",
"background_hex": "#F5F5F5",
"contrast_ratio": 13.21,
"foreground_luminance": 0.011,
"background_luminance": 0.913,
"compliant_normal_text": true,
"compliant_large_text": true,
"wcag_level": "AAA",
"context": "heading-large",
"created_at": "2026-03-26T10:00:00Z",
"updated_at": "2026-03-26T10:05:00Z"
}
DELETE
/api/v1/contrast-ratios/api/v1/contrast-ratios/:id
Delete a saved contrast ratio result
Public
Response Example
{
"deleted": true,
"id": "cr-003"
}
POST
/api/v1/contrast-ratios/api/v1/contrast-ratios/validate
One-off contrast validation without persisting
Public
Request Example
{
"foreground_hex": "#9E9E9E",
"background_hex": "#FFFFFF",
"text_role": "normal"
}
Response Example
{
"contrast_ratio": 3.95,
"compliant": false,
"wcag_level": "fail",
"minimum_required": 4.5,
"suggestion_foreground_hex": "#767676"
}