Skip to content

Todo API

Build a simple REST API with MinStack in minutes. This tutorial covers a single domain (todos), full CRUD, and — most importantly — how to write both unit tests and E2E tests.

What you'll build

A Todo API with five endpoints:

MethodPathDescription
GET/api/todosList all todos
POST/api/todosCreate a todo
GET/api/todos/:idGet a todo
PATCH/api/todos/:idUpdate a todo
DELETE/api/todos/:idDelete a todo

Final folder layout

todo-api/
├── cmd/
│   └── main.go
├── internal/todos/
│   ├── entities/todo.entity.go
│   ├── repositories/todo.repository.go
│   ├── dto/
│   │   ├── todo.dto.go
│   │   ├── create_todo.dto.go
│   │   └── update_todo.dto.go
│   ├── todo.service.go
│   ├── todo.service_test.go
│   ├── todo.controller.go
│   ├── todo.routes.go
│   └── module.go
├── e2e/
│   └── e2e_test.go
├── go.mod
└── .env

Steps

  1. Project Setupgo.mod, .env, directory scaffold
  2. Todos domain — entity, repository, DTOs, service, controller, routes, module
  3. Bootstrap — wiring everything in main.go and running the app
  4. Testing — unit tests with mocks and E2E tests with httptest