Designing for Consistency: API Style Guides and Standards
API style guide, naming conventions, camelCase vs snake_case, date formats, ISO 8601, boolean naming, pagination standards, error codes
Designing for Consistency: API Style Guides and Standards
A consistent REST API feels like it was designed by one person with a clear vision. In reality, most APIs are built by teams over months or years. An API style guide ensures that every endpoint, field name, error code, and response shape follows the same conventions, reducing the cognitive load on API consumers and maintainers alike.
Field Naming Conventions
Choose one naming convention and apply it everywhere. JSON APIs most commonly use camelCase (firstName, lastName, createdAt) because it matches JavaScript conventions. Some APIs use snake_case (first_name, last_name, created_at) for consistency with database column names. Never mix conventions within the same API.
Date and Time Formatting
Always use ISO 8601 format for dates and times: "createdAt": "2024-01-15T10:30:00Z". The Z suffix indicates UTC. This format is unambiguous, sortable, and parseable by every modern programming language. Never return Unix timestamps as your primary date format and never use locale-specific formats like MM/DD/YYYY.
Boolean Field Naming
Boolean fields should be named as questions or states that are clearly true or false: isActive, hasVerifiedEmail, isPremium. Avoid ambiguous names like status or active that could be mistaken for a string or verb.
Error Code Standards
Define a consistent error code taxonomy for your API: VALIDATION_ERROR, NOT_FOUND, UNAUTHORIZED, FORBIDDEN, RATE_LIMIT_EXCEEDED, INTERNAL_ERROR. Use SCREAMING_SNAKE_CASE for error codes — they are constants, not sentences. Document every error code and what it means.
Pagination Standards
Standardize your pagination approach across all collection endpoints. Cursor-based pagination is best for large datasets: ?after=cursor_abc&limit=20. Page-based pagination is simpler: ?page=3&limit=20. Always include total count, current page, and navigation links in the response metadata.
