API Design
Overview
Procedure for designing, implementing, and documenting effective APIs
Steps
Step 1: Understand requirements
Gather the context for API design:
- Identify use cases and user stories
- Understand who will consume the API
- List data entities and relationships
- Identify operations needed on each entity
- Understand non-functional requirements
- Review any existing APIs for consistency
Step 2: Design resource model
Define the API’s resource structure:
- Identify resources from entities
- Name resources (plural, lowercase, nouns)
- Define resource relationships
- Map operations to HTTP methods
- Design URL structure
- Identify sub-resources
Step 3: Design request/response schemas
Define what data flows in and out:
- Define resource schemas
- Design request bodies for create/update
- Design response bodies for each operation
- Plan pagination, filtering, sorting
- Design error response format
- Define common headers
Step 4: Design authentication and authorization
Define how security works:
- Choose authentication method
- Design authorization model
- Define which endpoints need auth
- Plan rate limiting
- Design API keys or tokens
- Consider security headers
Step 5: Create API specification
Document the complete API formally:
- Write OpenAPI specification
- Document each endpoint completely
- Include examples for all operations
- Document error codes and responses
- Specify authentication requirements
- Review specification for completeness
Step 6: Write documentation
Create consumer-facing documentation:
- Write getting started guide
- Create authentication guide
- Generate reference from OpenAPI
- Write guides for common use cases
- Include code examples in multiple languages
- Set up interactive API explorer
Step 7: Plan versioning and evolution
Prepare for API changes over time:
- Choose versioning strategy
- Define what constitutes breaking change
- Plan deprecation process
- Design for forward compatibility
- Plan changelog maintenance
- Document migration paths
When to Use
- Designing a new API for internal or external use
- Adding endpoints to existing API
- Reviewing API design before implementation
- Planning API versioning strategy
- Creating API documentation
- Defining error handling patterns
- Establishing API standards for a team
Verification
- API is RESTful and follows conventions
- All endpoints documented
- Error handling is comprehensive
- Authentication and authorization defined
- Documentation enables self-service
- Versioning strategy established
- API specification validates
Input: $ARGUMENTS
Apply this procedure to the input provided.