Skip to content

Latest commit

 

History

History
582 lines (440 loc) · 19.9 KB

File metadata and controls

582 lines (440 loc) · 19.9 KB

API Design Documentation - CleanArchitecture.ApiTemplate

"Great APIs are not just functional—they're intuitive, consistent, and a pleasure to use."

?? Overview

Welcome to the API Design documentation hub for CleanArchitecture.ApiTemplate. This guide serves as your starting point to understand how this project implements RESTful API best practices, versioning strategies, and comprehensive API documentation.

?? What You'll Find Here:

  • Complete RESTful API design principles
  • API versioning and backward compatibility strategies
  • Request/response contract examples
  • Error handling patterns
  • Performance optimization techniques
  • Security best practices for APIs
  • OpenAPI/Swagger documentation

?? Table of Contents

Quick Navigation

  1. What is RESTful API Design?
  2. Why This Implementation Matters
  3. API Status
  4. Documentation Structure
  5. Getting Started
  6. Quick Reference
  7. API Design Principles
  8. Related Documentation
  9. Contact & Support

?? What is RESTful API Design?

RESTful API Design provides:

  • ? Resource-based architecture - URLs represent resources, not actions
  • ? HTTP method semantics - GET, POST, PUT, DELETE, PATCH
  • ? Stateless communication - Each request contains all necessary information
  • ? Standard status codes - 200 OK, 201 Created, 400 Bad Request, etc.
  • ? Consistent response formats - JSON with predictable structure

API Versioning ensures:

  • ? Backward compatibility - Old clients continue to work
  • ? Graceful evolution - New features without breaking changes
  • ? Clear deprecation path - Phased retirement of old versions

This project demonstrates production-ready API design with .NET 8 and ASP.NET Core.


?? Why This Implementation Matters

For SecureClean Developers

This implementation demonstrates:

Challenge Solution in This Project
"How do I design consistent APIs?" Complete REST principles with resource naming conventions
"How do I version my API?" URL-based versioning (v1, v2) with backward compatibility
"How do I document my API?" Swagger/OpenAPI with comprehensive examples
"How do I handle errors consistently?" Standardized error responses with ProblemDetails
"How do I optimize API performance?" Caching strategies, async patterns, compression

Real-World Application

  • ?? Production-Ready - RESTful design with versioning and documentation
  • ??? Maintainable - Clear patterns make extending APIs straightforward
  • ?? Testable - Well-defined contracts enable comprehensive testing
  • ?? Self-Documenting - Swagger UI provides interactive documentation
  • ?? Scalable - Caching and async patterns support high traffic

?? API Status

Current Implementation: Complete REST API v1

CleanArchitecture.ApiTemplate API v1 (100% Complete)
??? Authentication/           [? 3 endpoints - Login, Logout, Token]
??? Sample Data/              [? 4 endpoints - CRUD operations]
??? Token Blacklist Admin/    [? 3 endpoints - Status, Stats, Health]
??? Versioning/               [? URL-based (v1)]
??? OpenAPI/Swagger/          [? Interactive documentation]
??? Error Handling/           [? ProblemDetails standard]

API Maturity

Component Status Key Features
REST Principles ? 100% Resource-based URLs, HTTP method semantics, stateless
Versioning ? 100% URL-based v1, backward compatibility, deprecation strategy
Documentation ? 100% Swagger/OpenAPI, interactive UI, code examples
Error Handling ? 100% ProblemDetails, consistent structure, HTTP status codes
Security ? 100% JWT authentication, rate limiting, CORS, security headers
Performance ? 100% Caching, async/await, compression, pagination ready
Testing ? 100% Complete test coverage, Swagger testing, Postman examples

?? Documentation Structure

?? Main Guides

1. API_DESIGN_GUIDE.md - ?? START HERE - Complete API Design Guide

Your comprehensive reference for API design principles and implementation.

What's Inside:

  • ? RESTful API design principles
  • ? HTTP methods and status codes
  • ? Resource naming conventions
  • ? URL structure and query parameters
  • ? API versioning strategy (URL-based v1)
  • ? Request/response formats (JSON)
  • ? Error handling with ProblemDetails
  • ? Pagination patterns (ready for implementation)
  • ? Caching strategies (Memory + Distributed)
  • ? Performance optimization techniques
  • ? Security best practices
  • ? CORS configuration
  • ? Rate limiting setup
  • ? Swagger/OpenAPI integration

When to Read: Start here to understand complete API design philosophy and implementation.

File Size: 48 KB - Comprehensive guide


2. API_CONTRACTS_EXAMPLES.md - Request/Response Examples

Real-world examples of all API endpoints with complete request/response contracts.

What's Inside:

  • ? Authentication endpoints (Login, Logout, Token generation)
  • ? Sample data endpoints (GET, POST, PUT, DELETE)
  • ? Token blacklist admin endpoints
  • ? Request body examples (JSON)
  • ? Response body examples (Success & Error)
  • ? HTTP status codes for each scenario
  • ? Header examples (Authorization, Content-Type)
  • ? Query parameter examples
  • ? Error response formats
  • ? cURL command examples

When to Read: After understanding principles, use this as a reference for specific endpoint contracts.

File Size: 21 KB - Practical examples


?? Getting Started

For New Developers (Start Here!)

Day 1: Understand API Design

  1. ?? Read this README (you're here!)
  2. ?? Read API_DESIGN_GUIDE.md - Complete principles
  3. ?? Review REST principles and HTTP semantics

Day 2: Explore Endpoints

  1. ?? Read API_CONTRACTS_EXAMPLES.md - All endpoints
  2. ?? Run the application: dotnet run
  3. ?? Open Swagger: https://localhost:7178/swagger
  4. ? Test endpoints interactively

Day 3: Test APIs

  1. ?? Review API Testing Guide
  2. ?? Test authentication flow (login, protected endpoints, logout)
  3. ?? Try all CRUD operations
  4. ?? Test error scenarios

For API Designers

Quick Assessment Path:

  1. ? API_DESIGN_GUIDE.md - Design principles and patterns
  2. ? API_CONTRACTS_EXAMPLES.md - Endpoint contracts
  3. ? API Testing Guide - Testing approach
  4. ? Swagger UI - Interactive documentation

Focus Areas:

  • RESTful resource design (URLs, HTTP methods)
  • Versioning strategy (URL-based v1)
  • Error handling (ProblemDetails standard)
  • Performance optimization (caching, async)
  • Security patterns (JWT, rate limiting)

For Team Leads

Evaluation Checklist:

  1. ?? API_DESIGN_GUIDE.md - API maturity and standards
  2. ?? API_CONTRACTS_EXAMPLES.md - Contract completeness
  3. ?? API Testing Guide - Test coverage
  4. ?? API Security Guide - Security posture

Team Onboarding:

  • Use API_DESIGN_GUIDE for design standards
  • Use API_CONTRACTS_EXAMPLES as reference for new endpoints
  • Use Swagger UI for interactive exploration
  • Review testing guide for quality assurance

?? Quick Reference

API Endpoints Summary

Authentication (3 endpoints)

Endpoint Method Auth Description
/api/v1/auth/login POST ? No User login with CQRS
/api/v1/auth/token GET ? No Quick token generation
/api/v1/auth/logout POST ? Yes Secure logout with blacklisting

Sample Data (4 endpoints)

Endpoint Method Auth Description
/api/v1/sample GET ? Yes Get all sample data
/api/v1/sample/{id} GET ? Yes Get specific item
/api/v1/sample POST ? Yes (Admin) Create new item
/api/v1/sample/admin GET ? Yes (Admin) Admin-only endpoint

Token Blacklist Admin (3 endpoints)

Endpoint Method Auth Description
/api/v1/token-blacklist/status GET ? Yes Check token status
/api/v1/token-blacklist/stats GET ? Yes (Admin) System statistics
/api/v1/token-blacklist/health GET ? No Health check

Total: 10 documented endpoints


HTTP Status Codes Used

Code Meaning When Used
200 OK Success Successful GET, PUT
201 Created Resource created Successful POST
204 No Content Success, no body Successful DELETE
400 Bad Request Client error Invalid input, validation errors
401 Unauthorized Not authenticated Missing/invalid token
403 Forbidden Not authorized Insufficient permissions
404 Not Found Resource missing Invalid ID, endpoint not found
429 Too Many Requests Rate limited Exceeded request limit
500 Internal Server Error Server error Unexpected server error

Versioning Strategy

Current: v1 (URL-based)

  • /api/v1/auth/login
  • /api/v1/sample

Future: v2 (when needed)

  • /api/v2/auth/login
  • /api/v2/sample

Benefits:

  • ? Clear version in URL
  • ? Easy to test multiple versions
  • ? Clients explicitly choose version
  • ? No breaking changes to existing clients

API Design Patterns

1. Resource Naming

? Good: /api/v1/users
? Bad:  /api/v1/getUsers

? Good: /api/v1/users/{id}
? Bad:  /api/v1/getUserById

? Good: /api/v1/auth/login
? Bad:  /api/v1/doLogin

2. HTTP Method Semantics

GET    /api/v1/users      ? List all users
GET    /api/v1/users/{id} ? Get specific user
POST   /api/v1/users      ? Create new user
PUT    /api/v1/users/{id} ? Update entire user
PATCH  /api/v1/users/{id} ? Update partial user
DELETE /api/v1/users/{id} ? Delete user

3. Query Parameters

/api/v1/users?page=1&pageSize=20       ? Pagination
/api/v1/users?sortBy=name&order=asc    ? Sorting
/api/v1/users?status=active            ? Filtering
/api/v1/users?search=john              ? Search

4. Error Response Format

{
  "type": "https://tools.ietf.org/html/rfc7231#section-6.5.1",
  "title": "Bad Request",
  "status": 400,
  "detail": "Username is required",
  "instance": "/api/v1/auth/login",
  "errors": {
    "Username": ["The Username field is required."]
  }
}

??? API Design Principles

1. RESTful Architecture

  • ? Resources represented by nouns (not verbs)
  • ? HTTP methods express actions
  • ? Stateless requests
  • ? Hierarchical URL structure
  • ? HATEOAS (ready for implementation)

2. Consistency

  • ? Predictable URL patterns
  • ? Standard HTTP status codes
  • ? Uniform error responses
  • ? Consistent naming conventions
  • ? Same authentication mechanism across all endpoints

3. Security

  • ? JWT Bearer authentication
  • ? Role-based authorization (User, Admin)
  • ? Rate limiting (60 req/min per IP)
  • ? CORS configuration
  • ? Security headers (XSS, Clickjacking protection)

4. Performance

  • ? Caching strategies (Memory + Distributed)
  • ? Async/await throughout
  • ? Compression enabled
  • ? Pagination ready
  • ? Response time logging

5. Documentation

  • ? Swagger/OpenAPI integration
  • ? Interactive testing UI
  • ? Request/response examples
  • ? Authentication flow documented
  • ? Error scenarios covered

?? Related Documentation

Testing

Security

Architecture

Deployment


?? Best Practices

API Design

  1. ? Use nouns for resources, not verbs
  2. ? Keep URLs simple and predictable
  3. ? Use HTTP methods correctly
  4. ? Return appropriate status codes
  5. ? Version your API from day one

Performance

  1. ? Implement caching for read-heavy endpoints
  2. ? Use async/await for I/O operations
  3. ? Enable response compression
  4. ? Implement pagination for large datasets
  5. ? Monitor and log response times

Security

  1. ? Always use HTTPS in production
  2. ? Validate all input
  3. ? Implement rate limiting
  4. ? Use proper authentication/authorization
  5. ? Keep dependencies updated

Documentation

  1. ? Document all endpoints
  2. ? Provide request/response examples
  3. ? Include error scenarios
  4. ? Keep Swagger UI updated
  5. ? Document breaking changes clearly

?? Summary

CleanArchitecture.ApiTemplate demonstrates production-ready API design with:

? RESTful architecture - Resource-based URLs, HTTP method semantics
? API versioning - URL-based v1 with backward compatibility
? Comprehensive documentation - Swagger/OpenAPI with interactive UI
? Standardized error handling - ProblemDetails with consistent structure
? Security - JWT authentication, rate limiting, CORS
? Performance - Caching, async patterns, compression
? Testing - Complete test coverage with Swagger and Postman examples
? Best practices - Following ASP.NET Core and REST conventions

This is not a tutorial project—it's a production implementation showcasing API design excellence in action.


?? Support & Contact

Need Help?

We're here to support you! Whether you have questions, found an issue, or need assistance with API implementation, here's how to reach us:


?? Contact Information

Contact Method Details
Email softevolutionsl@gmail.com
GitHub @dariemcarlosdev
Project Repository CleanArchitecture.ApiTemplate
Issues & Bug Reports GitHub Issues

?? Getting Help

For API Design Questions:

  1. ? Check API_DESIGN_GUIDE.md - Comprehensive principles
  2. ? Review API_CONTRACTS_EXAMPLES.md - Real examples
  3. ? Test with Swagger UI: https://localhost:7178/swagger
  4. ? Search existing GitHub Issues
  5. ? Open a new issue with specific questions

For Implementation Help:

  1. ? Review code examples in this documentation
  2. ? Check related guides (Testing, Security, Architecture)
  3. ? See actual implementation: Presentation/Controllers/v1/
  4. ? Check similar implementations in other endpoints
  5. ? Contact via email for detailed assistance

For Bug Reports:

  1. ?? Verify the issue with latest code
  2. ?? Check if already reported in GitHub Issues
  3. ?? Include: Steps to reproduce, expected vs actual behavior, environment details
  4. ?? Provide relevant logs or error messages
  5. ?? Submit via GitHub Issues

For Feature Requests:

  1. ?? Check roadmap and existing feature requests
  2. ?? Describe the use case and expected behavior
  3. ?? Explain how it benefits the API design
  4. ?? Submit via GitHub Issues with "Feature Request" label

?? Documentation Feedback

Found something unclear or missing in the documentation?

  • Typos or errors: Open a GitHub Issue or submit a Pull Request
  • Missing examples: Let us know what examples would be helpful
  • Improvement suggestions: We welcome all feedback to make docs better
  • New topics: Suggest additional topics you'd like to see covered

?? Contributing

Interested in contributing to CleanArchitecture.ApiTemplate?

  1. ? Star the repository
  2. ?? Fork the project
  3. ?? Make your changes
  4. ? Ensure all tests pass
  5. ?? Update documentation if needed
  6. ?? Submit a Pull Request

Contribution Guidelines:

  • Follow existing code style and conventions
  • Write clear commit messages
  • Update relevant documentation
  • Add tests for new features
  • Ensure backwards compatibility

? Quick Support Links

Need Resource
Quick Start Getting Started
API Reference Quick Reference
Testing Help API Testing Guide
Security Help API Security Guide
Architecture Help Clean Architecture Hub
Deployment Help Deployment README
Report Issue GitHub Issues

?? Community

  • Discussions: Use GitHub Discussions for general questions and community interaction
  • Best Practices: Share your API design patterns and learnings
  • Showcase: Share projects built using CleanArchitecture.ApiTemplate patterns
  • Feedback: Help us improve by sharing your experience

?? Stay Updated

  • Watch the repository for updates and new releases
  • Star to show support and stay informed
  • Follow @dariemcarlosdev for project updates

? Response Times

Type Expected Response
Critical Bugs Within 24-48 hours
General Questions Within 2-3 business days
Feature Requests Within 1 week for initial feedback
Documentation Issues Within 1-2 business days

Note: This is an open-source project maintained by volunteers. Response times may vary.


?? License & Legal

This project is open source. Please review the license terms before using in production.

Contact for:

  • Commercial support inquiries
  • Custom implementation assistance
  • Training and workshops
  • Enterprise consulting

?? Email: softevolutionsl@gmail.com


Last Updated: January 2025
Maintainer: Dariemcarlos
Project: CleanArchitecture.ApiTemplate
Status: ? Production-Ready
Version: 1.0.0 - Complete API Design Hub


Happy API Designing! ??