Skip to main content
In this tutorial, you’ll build a todo list API with full CRUD operations. CRUD stands for Create, Read, Update, Delete - the four basic operations for managing data. This is the foundation of almost every web application, and you’ll learn the patterns used in production Mizu APIs.

What We’re Building

A REST API with these endpoints:

Step 1: Create the Project

Verify it works:
You should see {"status":"ok"}.

Step 2: Create the Todo Feature

Create the feature directory:
Create feature/todos/http.go:
This sets up our data types and a simple in-memory store.

Step 3: Implement List Handler

Add to feature/todos/http.go:

Step 4: Implement Create Handler

Add to feature/todos/http.go:

Step 5: Implement Get Handler

Add to feature/todos/http.go:

Step 6: Implement Update Handler

Add to feature/todos/http.go:

Step 7: Implement Delete Handler

Add to feature/todos/http.go:

Step 8: Register Routes

Update app/api/app.go to include the store:
Update app/api/routes.go:

Step 9: Test the API

Start the server:
In another terminal, test each endpoint:

List (empty)

Output: []

Create

Output:

Create Another

List All

Output:

Get One

Update

Output:

Delete

Output:

Complete Code

Here’s the complete feature/todos/http.go:

What You Learned

  1. Feature organization - Grouping related code together
  2. Handler factories - Functions that return handlers
  3. Dependency injection - Passing the store to handlers
  4. CRUD operations - Create, Read, Update, Delete patterns
  5. Input validation - Checking required fields
  6. Error responses - Returning appropriate status codes

Next Steps

Add a Database

Replace in-memory store with a real database

Contract Template

Learn about multi-protocol APIs

Add Middleware

Add logging, auth, and more

Error Handling

Improve error responses