This project demonstrates a .NET 8 Web API with a standardized API response model, CRUD operations for student management, and Entity Framework Core for database interactions.
- Standardized API Response: All API endpoints return responses wrapped in a consistent
ApiResponse<T>
model, including status codes, success/failure indicators, data payload, error messages, and timestamps. - Student Management: CRUD operations for
StudentDetails
andStudentSubject
entities. - Data Annotation Validation: Request validation and input sanitization using data annotations.
- Entity Framework Core: Database interaction with PostgreSQL using EF Core migrations.
- Global Error Handling: Centralized error handling to provide consistent error responses.
- .NET 8 SDK
- PostgreSQL database server
- Redis (optional, for caching)
Update the appsettings.json
file with your database connection string and other settings:
{
"ConnectionStrings": {
"DefaultConnection": "Host=localhost;Port=5432;Database=DummyDb;Username=postgres;Password=system",
"RedisConnection": "localhost:6379"
},
"JwtSettings": {
"Secret": "YOUR_SUPER_SECRET_KEY_THAT_IS_AT_LEAST_32_CHARS_LONG",
"Issuer": "TableByModel",
"Audience": "TableByModelClient"
}
}
Apply database migrations to create the necessary tables:
dotnet ef database update
dotnet run
The application will start and listen on http://localhost:5160
(or the port configured in launchSettings.json
).
Access the Swagger UI at http://localhost:5160/swagger
to explore and test the API endpoints.
Controllers/
: Contains API controllers, e.g.,StudentController.cs
.Response/
: Defines theApiResponse.cs
model for standardized responses.Filters/
: IncludesApiResponseFilter.cs
for wrapping API responses.Model/
: Contains entity models, e.g.,StudentDetails.cs
.Services/
: Business logic and data access, e.g.,StudentService.cs
.AppDbContext.cs
: Entity Framework Core DbContext for database interaction.Migrations/
: Database migration files.