api-patterns
Use when creating or modifying API endpoints. Provides REST conventions and error handling patterns for this project.
When & Why to Use This Skill
This Claude skill streamlines the development and maintenance of API endpoints by enforcing standardized REST conventions, consistent JSON response structures, and robust error handling patterns. It serves as an architectural blueprint to ensure that all web services within a project remain scalable, predictable, and easy to integrate.
Use Cases
- Standardizing Endpoint Design: Use the skill to quickly scaffold RESTful routes (GET, POST, PUT, DELETE) that follow project-specific naming conventions and resource hierarchies.
- Implementing Unified Response Formats: Ensure all API responses return a consistent JSON wrapper, making it easier for frontend teams to parse data and handle success/failure states.
- Enhancing Error Management: Apply predefined HTTP status codes and error messaging patterns to provide clear, actionable feedback for debugging and client-side error handling.
- Onboarding and Documentation: Serve as a live reference for new developers to understand the project's API architecture and coding standards through concrete examples.
| name | api-patterns |
|---|---|
| description | Use when creating or modifying API endpoints. Provides REST conventions and error handling patterns for this project. |
API Patterns for Pet Adoption Center
Endpoint Conventions
- GET /pets - List all pets
- GET /pets/{id} - Get single pet
- POST /pets - Create pet
- PUT /pets/{id} - Update pet
- DELETE /pets/{id} - Delete pet
Response Format
Always return JSON with this structure:
{
"success": True,
"data": {...},
"error": None
}
Error Handling
Use HTTP status codes:
- 200: Success
- 201: Created
- 400: Bad request
- 404: Not found
- 500: Server error
Example Endpoint
@app.route('/pets', methods=['GET'])
def list_pets():
try:
pets = Pet.query.all()
return jsonify(success=True, data=[p.to_dict() for p in pets])
except Exception as e:
return jsonify(success=False, error=str(e)), 500