|
| 1 | +--- |
| 2 | +description: 'Guidelines for building REST APIs with ASP.NET' |
| 3 | +applyTo: '**/*.cs, **/*.json' |
| 4 | +--- |
| 5 | + |
| 6 | +# ASP.NET REST API Development |
| 7 | + |
| 8 | +## Instruction |
| 9 | +- Guide users through building their first REST API using ASP.NET Core 9. |
| 10 | +- Explain both traditional Web API controllers and the newer Minimal API approach. |
| 11 | +- Provide educational context for each implementation decision to help users understand the underlying concepts. |
| 12 | +- Emphasize best practices for API design, testing, documentation, and deployment. |
| 13 | +- Focus on providing explanations alongside code examples rather than just implementing features. |
| 14 | + |
| 15 | +## API Design Fundamentals |
| 16 | + |
| 17 | +- Explain REST architectural principles and how they apply to ASP.NET Core APIs. |
| 18 | +- Guide users in designing meaningful resource-oriented URLs and appropriate HTTP verb usage. |
| 19 | +- Demonstrate the difference between traditional controller-based APIs and Minimal APIs. |
| 20 | +- Explain status codes, content negotiation, and response formatting in the context of REST. |
| 21 | +- Help users understand when to choose Controllers vs. Minimal APIs based on project requirements. |
| 22 | + |
| 23 | +## Project Setup and Structure |
| 24 | + |
| 25 | +- Guide users through creating a new ASP.NET Core 9 Web API project with the appropriate templates. |
| 26 | +- Explain the purpose of each generated file and folder to build understanding of the project structure. |
| 27 | +- Demonstrate how to organize code using feature folders or domain-driven design principles. |
| 28 | +- Show proper separation of concerns with models, services, and data access layers. |
| 29 | +- Explain the Program.cs and configuration system in ASP.NET Core 9 including environment-specific settings. |
| 30 | + |
| 31 | +## Building Controller-Based APIs |
| 32 | + |
| 33 | +- Guide the creation of RESTful controllers with proper resource naming and HTTP verb implementation. |
| 34 | +- Explain attribute routing and its advantages over conventional routing. |
| 35 | +- Demonstrate model binding, validation, and the role of [ApiController] attribute. |
| 36 | +- Show how dependency injection works within controllers. |
| 37 | +- Explain action return types (IActionResult, ActionResult<T>, specific return types) and when to use each. |
| 38 | + |
| 39 | +## Implementing Minimal APIs |
| 40 | + |
| 41 | +- Guide users through implementing the same endpoints using the Minimal API syntax. |
| 42 | +- Explain the endpoint routing system and how to organize route groups. |
| 43 | +- Demonstrate parameter binding, validation, and dependency injection in Minimal APIs. |
| 44 | +- Show how to structure larger Minimal API applications to maintain readability. |
| 45 | +- Compare and contrast with controller-based approach to help users understand the differences. |
| 46 | + |
| 47 | +## Data Access Patterns |
| 48 | + |
| 49 | +- Guide the implementation of a data access layer using Entity Framework Core. |
| 50 | +- Explain different options (SQL Server, SQLite, In-Memory) for development and production. |
| 51 | +- Demonstrate repository pattern implementation and when it's beneficial. |
| 52 | +- Show how to implement database migrations and data seeding. |
| 53 | +- Explain efficient query patterns to avoid common performance issues. |
| 54 | + |
| 55 | +## Authentication and Authorization |
| 56 | + |
| 57 | +- Guide users through implementing authentication using JWT Bearer tokens. |
| 58 | +- Explain OAuth 2.0 and OpenID Connect concepts as they relate to ASP.NET Core. |
| 59 | +- Show how to implement role-based and policy-based authorization. |
| 60 | +- Demonstrate integration with Microsoft Entra ID (formerly Azure AD). |
| 61 | +- Explain how to secure both controller-based and Minimal APIs consistently. |
| 62 | + |
| 63 | +## Validation and Error Handling |
| 64 | + |
| 65 | +- Guide the implementation of model validation using data annotations and FluentValidation. |
| 66 | +- Explain the validation pipeline and how to customize validation responses. |
| 67 | +- Demonstrate a global exception handling strategy using middleware. |
| 68 | +- Show how to create consistent error responses across the API. |
| 69 | +- Explain problem details (RFC 7807) implementation for standardized error responses. |
| 70 | + |
| 71 | +## API Versioning and Documentation |
| 72 | + |
| 73 | +- Guide users through implementing and explaining API versioning strategies. |
| 74 | +- Demonstrate Swagger/OpenAPI implementation with proper documentation. |
| 75 | +- Show how to document endpoints, parameters, responses, and authentication. |
| 76 | +- Explain versioning in both controller-based and Minimal APIs. |
| 77 | +- Guide users on creating meaningful API documentation that helps consumers. |
| 78 | + |
| 79 | +## Logging and Monitoring |
| 80 | + |
| 81 | +- Guide the implementation of structured logging using Serilog or other providers. |
| 82 | +- Explain the logging levels and when to use each. |
| 83 | +- Demonstrate integration with Application Insights for telemetry collection. |
| 84 | +- Show how to implement custom telemetry and correlation IDs for request tracking. |
| 85 | +- Explain how to monitor API performance, errors, and usage patterns. |
| 86 | + |
| 87 | +## Testing REST APIs |
| 88 | + |
| 89 | +- Guide users through creating unit tests for controllers, Minimal API endpoints, and services. |
| 90 | +- Explain integration testing approaches for API endpoints. |
| 91 | +- Demonstrate how to mock dependencies for effective testing. |
| 92 | +- Show how to test authentication and authorization logic. |
| 93 | +- Explain test-driven development principles as applied to API development. |
| 94 | + |
| 95 | +## Performance Optimization |
| 96 | + |
| 97 | +- Guide users on implementing caching strategies (in-memory, distributed, response caching). |
| 98 | +- Explain asynchronous programming patterns and why they matter for API performance. |
| 99 | +- Demonstrate pagination, filtering, and sorting for large data sets. |
| 100 | +- Show how to implement compression and other performance optimizations. |
| 101 | +- Explain how to measure and benchmark API performance. |
| 102 | + |
| 103 | +## Deployment and DevOps |
| 104 | + |
| 105 | +- Guide users through containerizing their API using .NET's built-in container support (`dotnet publish --os linux --arch x64 -p:PublishProfile=DefaultContainer`). |
| 106 | +- Explain the differences between manual Dockerfile creation and .NET's container publishing features. |
| 107 | +- Explain CI/CD pipelines for ASP.NET Core applications. |
| 108 | +- Demonstrate deployment to Azure App Service, Azure Container Apps, or other hosting options. |
| 109 | +- Show how to implement health checks and readiness probes. |
| 110 | +- Explain environment-specific configurations for different deployment stages. |
0 commit comments