A small REST + JSON service in Go: an in-memory task list with mutex-safe storage, standard-library HTTP, and a layout ready to grow (tests, Docker, CI).
Created by Aksel.
net/http(Go 1.22+ route patterns),encoding/jsoninternal/packages:store(concurrent in-memory map),api(handlers + router)GET /healthfor load balancers and containers- Unit tests (
httptest, table-free integration-style handler tests) - Multi-stage Dockerfile, docker compose, Makefile
- GitHub Actions:
go vet, tests with-race, build
.
├── cmd/server/ # main entrypoint
├── internal/
│ ├── api/ # HTTP handlers and router
│ └── store/ # in-memory task store
├── Dockerfile
├── docker-compose.yml
├── Makefile
└── .github/workflows/ # CI
- Go 1.22+ (uses
ServeMuxmethod and path patterns)
git clone https://github.com/YOUR_GITHUB_USERNAME/todo-api.git
cd todo-api
go run ./cmd/serverServer listens on http://localhost:8080 unless PORT is set.
| Variable | Default | Description |
|---|---|---|
PORT |
8080 |
Listen port (e.g. 3000 → :3000) |
| Method | Path | Description |
|---|---|---|
GET |
/health |
Liveness: {"status":"ok"} |
GET |
/tasks |
List tasks (sorted by numeric id) |
POST |
/tasks |
Create task: JSON {"title":"string"} (title trimmed, required) |
POST |
/tasks/{id}/toggle |
Toggle done |
DELETE |
/tasks/{id} |
Delete task (204 on success) |
# Health
curl -s http://localhost:8080/health
# Create
curl -s -X POST http://localhost:8080/tasks \
-H 'Content-Type: application/json' \
-d '{"title":"Learn Go modules"}'
# List
curl -s http://localhost:8080/tasks
# Toggle done
curl -s -X POST http://localhost:8080/tasks/1/toggle
# Delete
curl -s -o /dev/null -w "%{http_code}\n" -X DELETE http://localhost:8080/tasks/1make docker-build # image: todo-api:local
make docker-up # compose: http://localhost:8080Or:
docker compose up --buildmake test # race detector
make vet
make build # writes ./todo-api- Create a new repository on GitHub (empty, no README if you push this tree as-is).
- Replace the module path in
go.modand imports with your repo, for example:module github.com/<you>/todo-api- Update import paths under
cmd/andinternal/to match.
- Replace
YOUR_GITHUB_USERNAMEin this README (badge + clone URL). - Push:
git init
git add .
git commit -m "Initial commit: todo JSON API"
git branch -M main
git remote add origin https://github.com/<you>/todo-api.git
git push -u origin mainApache License 2.0 — see LICENSE.