A complete Todo API built with .NET Core 8, Entity Framework Core, PostgreSQL, and FastEndpoints, containerized with Docker.
- ✅ FastEndpoints - High-performance endpoint-based architecture
- ✅ Vertical Slice Architecture - Feature-based organization
- ✅ Built-in Validation - FluentValidation integration
- ✅ Entity Framework Core with PostgreSQL
- ✅ Database Migrations with automatic application
- ✅ Docker Containerization - Multi-container setup
- ✅ Swagger Documentation - Auto-generated API docs
- ✅ .http File - API testing and exploration with Visual Studio
- ✅ Razor Page served as the Home Page
- ✅ Priority System - Low, Medium, High priorities
- ✅ Filtering & Querying - Filter by status and priority
Features/Todos/
├── GetTodos/GetTodosEndpoint.cs # GET /api/todos
├── GetTodoById/GetTodoByIdEndpoint.cs # GET /api/todos/{id}
├── CreateTodo/CreateTodoEndpoint.cs # POST /api/todos
├── UpdateTodo/UpdateTodoEndpoint.cs # PUT /api/todos/{id}
├── CompleteTodo/CompleteTodoEndpoint.cs # PATCH /api/todos/{id}/complete
└── DeleteTodo/DeleteTodoEndpoint.cs # DELETE /api/todos/{id}
Each endpoint contains:
- Request/Response Models - Data contracts
- Validation Rules - FluentValidation rules
- Handler Logic - Business logic implementation
- Configuration - Route, security, and documentation
- Clone the repository.
- From your project directory, run the application:
docker-compose up --build
- Access the services:
- API:
http://localhost:6060
- Swagger Documentation:
http://localhost:6060//swagger
- pgAdmin:
http://localhost:5050
- API:
- Open pgAdmin at
http://localhost:5050
- Login with:
- Email:
admin@todoapi.com
- Password:
admin123
- Email:
- Add a new server connection:
- Host:
postgres
- Port:
5432
- Database:
TodoDb
- Username:
postgres
- Password:
postgres123
- Host:
- Install .NET 8 SDK
- Install PostgreSQL
- Update connection string in
appsettings.json
- If needed, install the
dotnet ef
tool:dotnet tool install --global dotnet-ef
- Run migrations:
This will create the
dotnet ef database update
Migrations
folder and apply the initial migration to set up the database schema. - Start the application:
dotnet run
Method | Endpoint | Description |
---|---|---|
GET | /api/todos |
Get all todos (with filtering) |
GET | /api/todos/{id} |
Get todo by ID |
POST | /api/todos |
Create new todo |
PUT | /api/todos/{id} |
Update todo |
PATCH | /api/todos/{id}/complete |
Mark todo as complete |
DELETE | /api/todos/{id} |
Delete todo |
isCompleted
(bool) - Filter by completion statuspriority
(enum) - Filter by priority level
- Performance - ~2x faster than traditional controllers
- Type Safety - Strongly typed requests/responses
- Built-in Validation - Automatic request validation
- Minimal Boilerplate - Less code, more functionality
- Self-Documenting - Integrated Swagger generation
- Testability - Easy unit testing without mocking
The TodoItem
entity includes:
Id
(Primary Key)Title
(Required, max 200 chars)Description
(Optional, max 1000 chars)IsCompleted
(Boolean, default false)CreatedAt
(Timestamp)CompletedAt
(Nullable timestamp)Priority
(Enum: Low=1, Medium=2, High=3)
ConnectionStrings__DefaultConnection
- PostgreSQL connection stringASPNETCORE_ENVIRONMENT
- Environment (Development/Production)
# Add new migration
dotnet ef migrations add MigrationName
# Update database
dotnet ef database update
# Remove last migration
dotnet ef migrations remove
# Generate SQL script
dotnet ef migrations script