Should a REST API return 200 OK when validation fails?
No. Return 400 Bad Request or 422 Unprocessable Content so API gateways, APM dashboards, and HTTP retry libraries accurately detect failures.
HTTP 200 OK confirms a successful request. In production APIs and CDNs, the real engineering work is pairing 200 responses with proper Cache-Control, ETag, Brotli compression, and security headers.
location ~* \.(js|css|svg|woff2)$ {
add_header Cache-Control "public, max-age=31536000, immutable" always;
add_header X-Content-Type-Options "nosniff" always;
}
location /api/ {
add_header Cache-Control "no-store" always;
add_header Vary "Origin, Authorization" always;
}
curl -i -sS -H 'Accept-Encoding: br, gzip' https://example.com/api/health
No. Return 400 Bad Request or 422 Unprocessable Content so API gateways, APM dashboards, and HTTP retry libraries accurately detect failures.
Cloudflare caches 200 OK responses for static file extensions by default, and for HTML/JSON only when Cache Rules or explicit Cache-Control headers allow it.
Always include Strict-Transport-Security, Content-Security-Policy, X-Content-Type-Options: nosniff, Referrer-Policy, and Permissions-Policy.