API Endpoint Design

MR
@Mike Rodriguez
4 days ago
Fork

Design a RESTful API endpoint for {{feature_description}}.

Context

  • Application: {{app_context}}
  • Existing Entities: {{existing_entities}}
  • Authentication: {{auth_method}}

Deliverables

1. Endpoint Specification

URL Structure
{{http_method}} /api/v1/{{resource}}
Request
  • Headers (required and optional)
  • Path parameters
  • Query parameters
  • Request body (JSON schema)
Response
  • Success response (200/201)
  • Error responses (400, 401, 403, 404, 500)
  • Pagination format (if list endpoint)

2. Data Validation

  • Required fields
  • Field types and constraints
  • Custom validation rules

3. Error Handling

Standard error response format:

{
  "error": {
    "code": "VALIDATION_ERROR",
    "message": "Human readable message",
    "details": []
  }
}

4. Database Considerations

  • Required indexes
  • Query optimization notes
  • Transaction requirements

5. Security Checklist

  • Authentication required?
  • Authorization (who can access?)
  • Rate limiting
  • Input sanitization
  • SQL injection prevention
  • Sensitive data handling

6. OpenAPI Spec (Swagger)

Provide the endpoint in OpenAPI 3.0 format

7. Example Implementation

Basic implementation in {{language}}

Variables 7

Feature Description {{feature_description}}
e.g., User can update their profile information including avatar upload
Application Context {{app_context}}
e.g., SaaS project management tool with multi-tenant architecture
Existing Entities {{existing_entities}}
e.g., Users, Organizations, Projects, Tasks
Authentication Method {{auth_method}}
e.g., JWT Bearer token, API key, OAuth 2.0
HTTP Method {{http_method}}
e.g., GET, POST, PUT, PATCH, DELETE
Resource Name {{resource}}
e.g., users, projects/{id}/tasks
Implementation Language {{language}}
e.g., Node.js/Express, Python/FastAPI, Go