Overview

This example presents a simple but complete todo list application.

View the complete source on the Encore Playground.

If you are not yet experienced with how an Encore project is structured, consider starting with the tutorial for a more detailed explanation of the basics of writing Encore applications.

API Design

The application will have a single service: todo. This service will have APIs to add, update, and list todo items. Each todo item will have an id, a title, and whether or not it is done.

Let's start by defining the API.

Adding a todo item

// Item is a todo item.
type Item struct {
    ID    int64
    Title string
    Done  bool
}

type AddParams struct {
    Title string
}

// Add adds a todo item. It returns the created todo item.
//encore:api public
func Add(ctx context.Context, params *AddParams) (*Item, error) {
    // ...
}

Updating a todo item

type UpdateParams struct {
	ID   int64
	Done bool
}

// Update updates the done state of a todo item.
//encore:api public
func Update(ctx context.Context, params *UpdateParams) error {
    // ...
}

Listing todo items

type ListResponse struct {
    Items []*Item
}

// List lists all todo items.
//encore:api public
func List(ctx context.Context) (*ListResponnse, error) {
    // ...
}

Next steps

We are now ready to get started on the implementation. Head on over to the Implementation section.

Subscribe to our Engineering Blog

The latest ideas to help you build better software.

You can unsubscribe at any time.

© 2020 Encore. All rights reserved.