A task management REST API built with Go and the Gin framework. This implementation provides CRUD operations for tasks with support for pagination, filtering, and status management.
.
├── cmd/
│ └── rest-server/ # REST server entry point
│ └── main.go
├── internal/ # Private application code
│ ├── models/ # Data models and types
│ │ └── task.go
│ └── services/ # Business logic
│ └── task_service.go
├── rest/ # REST API implementation
│ └── server/ # HTTP handlers and routing
│ └── handlers.go
├── go.mod # Go module definition
└── README.md
- Go 1.21 or higher
# Download dependencies
go mod download# Run directly
go run cmd/rest-server/main.go
# Or build and run
go build -o bin/rest-server cmd/rest-server/main.go
./bin/rest-serverPort Configuration:
The server reads the port from the PORT environment variable. If not set, it defaults to 8080.
# Run on custom port
PORT=3000 go run cmd/rest-server/main.goGET /health- Server health status
GET /api/v1/tasks- List all tasks- Query params:
page_size,page_token,status,assigned_to,tags,sort_order
- Query params:
GET /api/v1/tasks/:id- Get a specific taskPOST /api/v1/tasks- Create a new taskPUT /api/v1/tasks/:id- Update a taskPATCH /api/v1/tasks/:id/status- Update task status onlyDELETE /api/v1/tasks/:id- Delete a task
pending- Task is pendingin_progress- Task is being worked oncompleted- Task is completedcancelled- Task is cancelledon_hold- Task is on hold
low- Low prioritymedium- Medium priorityhigh- High prioritycritical- Critical priority
{
"id": "uuid",
"title": "string (required, 1-200 chars)",
"description": "string",
"status": "TaskStatus",
"priority": "TaskPriority",
"tags": ["string"],
"created_by": "string",
"assigned_to": "string (optional)",
"created_at": "timestamp",
"updated_at": "timestamp",
"due_date": "timestamp (optional)",
"completed_at": "timestamp (optional)"
}curl -X POST http://localhost:8080/api/v1/tasks \
-H "Content-Type: application/json" \
-d '{
"title": "Learn Go",
"description": "Complete the Go tutorial",
"priority": "high",
"tags": ["learning", "go"]
}'# All tasks
curl http://localhost:8080/api/v1/tasks
# Filtered by status
curl http://localhost:8080/api/v1/tasks?status=pending
# With pagination
curl http://localhost:8080/api/v1/tasks?page_size=10&sort_order=priority_desccurl -X PATCH http://localhost:8080/api/v1/tasks/{id}/status \
-H "Content-Type: application/json" \
-d '{"status": "in_progress"}'curl -X DELETE http://localhost:8080/api/v1/tasks/{id}- Gin Framework - Fast HTTP router with middleware support
- In-memory Storage - Task data stored in memory (no database required)
- Validation - Request validation with struct tags
- Error Handling - Consistent error responses with status codes
- CORS Support - Cross-origin resource sharing enabled
- Pagination - Page-based pagination with tokens
- Filtering & Sorting - Query by status, assignee, tags; sort by various fields
- UUID-based IDs - Unique identifiers for all tasks
200 OK- Successful GET/PUT/PATCH request201 Created- Successful POST request204 No Content- Successful DELETE request400 Bad Request- Validation error or invalid input404 Not Found- Resource not found500 Internal Server Error- Server error
{
"error": {
"code": "ERROR_CODE",
"message": "Human readable error message"
}
}Common error codes:
VALIDATION_ERROR- Invalid input dataNOT_FOUND- Resource not foundINTERNAL_ERROR- Server error