Overview
This guide covers how to extend the API with new features, add endpoints, implement service methods, and follow best practices for development.Development Workflow
Hot Reload for Fast Development
Usedotnet watch for automatic reloading:
.cs files, the application automatically recompiles and restarts.
Implementing Service Methods
Currently, service implementations throwNotImplementedException. Let’s implement them.
Example: Implementing PacienteService
Services/PacienteService.cs
Implementing CitaService with Business Logic
Services/CitaService.cs
When CitaService depends on other services, update the registration in
Program.cs to inject dependencies:Adding New Endpoints
Step 1: Update the Controller
Add HTTP endpoint methods to controllers:Controllers/PacienteController.cs
Step 2: Verify OpenAPI Documentation
The OpenAPI specification updates automatically. Visit:Adding Custom Endpoints
Example: Get Appointments by Patient
Add a custom endpoint to get all appointments for a specific patient:Controllers/CitaController.cs
Example: Get Appointments by Status
Example: Cancel Appointment
Adding Data Validation
Using Data Annotations
Add validation attributes to DTOs:Models/Dtos/CreatePacienteDto.cs
Custom Validation Attributes
Create custom validators:Validation/EdadMinimaAttribute.cs
Adding Logging
Use ASP.NET Core’s built-in logging:Controllers/PacienteController.cs
Migrating to a Database
Step 1: Install Entity Framework Core
Step 2: Create DbContext
Data/AppDbContext.cs
Step 3: Configure in Program.cs
Step 4: Add Connection String
appsettings.json
Step 5: Update Service Implementation
Step 6: Create Migrations
Best Practices
Use Dependency Injection
Always inject dependencies via constructors, never use
newValidate Input
Use Data Annotations and service-layer validation
Handle Errors Properly
Catch specific exceptions and return appropriate HTTP status codes
Log Important Events
Use ILogger to track operations and errors
Keep Controllers Thin
Move all business logic to services
Use DTOs
Separate API contracts from internal models
Next Steps
Testing Guide
Learn how to test your API
Architecture
Understand the overall architecture
Services
Deep dive into service patterns
API Reference
Browse all available endpoints