A REST API built in Go for managing tasks with user authentication, search, filtering, pagination, and business rule enforcement.
- Go — core language
- chi — HTTP router
- golang-jwt/jwt — JWT authentication
- google/uuid — unique task IDs
- In-memory store — no database required
task-api/
├── main.go # Entry point, route registration
├── models/
│ ├── task.go # Task struct and Status constants
│ └── user.go # User struct
├── handlers/
│ └── task.go # HTTP handlers (Login, CRUD)
├── middleware/
│ └── auth.go # JWT validation middleware
├── store/
│ ├── task_store.go # In-memory data layer + business logic
│ └── task_store_test.go # Unit tests
└── go.mod
go mod tidygo run main.goServer runs at http://localhost:8000
go test ./store/... -v| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /login |
Login and get JWT token | No |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /tasks |
Create a new task | Yes |
| GET | /tasks |
List all tasks | Yes |
| GET | /tasks/{id} |
Get a single task | Yes |
| PUT | /tasks/{id} |
Update a task | Yes |
| DELETE | /tasks/{id} |
Delete a task | Yes |
{
"ID": "uuid",
"Title": "Fix login bug",
"Description": "The login page crashes on mobile",
"Status": "TODO",
"UserId": "1",
"CreatedAt": "2026-04-07T10:00:00Z",
"UpdatedAt": "2026-04-07T11:00:00Z"
}Status values: TODO | IN_PROGRESS | DONE
POST /login
Content-Type: application/json
{
"username": "john",
"password": "1234"
}Response:
{
"token": "eyJhbGciOiJIUzI1NiIs..."
}POST /tasks
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Fix login bug",
"description": "Crashes on mobile",
"status": "TODO"
}GET /tasks?status=TODO&q=fix&page=1&limit=5
Authorization: Bearer <token>| Query Param | Description | Example |
|---|---|---|
status |
Filter by status | ?status=TODO |
q |
Search in title/description | ?q=bug |
page |
Page number (default: 1) | ?page=2 |
limit |
Items per page (default: 10) | ?limit=5 |
PUT /tasks/{id}
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Fix login bug",
"description": "Fixed on mobile",
"status": "DONE"
}DELETE /tasks/{id}
Authorization: Bearer <token>- Max 3 IN_PROGRESS tasks per user — attempting to create or update a 4th task to
IN_PROGRESSreturns400 Bad Request - Task ownership — users can only view, update, or delete their own tasks. Accessing another user's task returns
403 Forbidden - Token expiry — JWT tokens expire after 24 hours
username: john
password: 1234
| Test | What it covers |
|---|---|
TestCreateTask |
Task is created with a valid ID |
TestCreateTask_3InProgressLimit |
4th IN_PROGRESS task is rejected |
TestGetTask_NotFound |
Returns error for non-existent task |
TestUpdateTask_StatusChange |
Blocks status change when limit is hit |
TestDeleteTask |
Task is removed from the store |
TestGetAllTasks_Filter |
Returns only tasks matching the filter |
TestGetAllTasks_Pagination |
Returns correct page slice |