Completing the REST API Server

Powerful Command-Line Applications in Go — by Ricardo Gerardi (87 / 127)

The Pragmatic Programmers
The Pragmatic Programmers

--

👈 Testing the REST API Server | TOC | Developing the Initial Client for th e REST API 👉

With the general structure of your API server ready, let’s add the CRUD operations for the to-do list. You’ll use the to-do API you developed in Defining the To-Do API.

Your to-do REST API supports these operations:

Table 1. To-Do REST API Operations

The REST API serves all to-do — related content using the /todo URL path. It handles different operations based on the HTTP method, path, and parameters. The path may include a number for operations that act on a single to-do item. For example, to delete the third item from the list, the user sends a DELETE request to the URL path /todo/3.

The first two GET operations on the list retrieve items from the list. For this example, the REST API responds with JSON data. Besides the to-do items, we want to include additional information with the response, such as the current date and the number of results included. A sample response for multiple items looks like this:

​ {
​ ​"results"​: [
​…

--

--

The Pragmatic Programmers
The Pragmatic Programmers

We create timely, practical books and learning resources on classic and cutting-edge topics to help you practice your craft and accelerate your career.