Adding an Item
So far, your to-do REST API client is able to get all the items from the list and view details about specific items. Let’s include the ability to add new items to the list so users can track their new tasks.
To add new tasks to the to-do list using your REST API, the client must send an HTTP POST request to the /todo endpoint containing the task as a JSON payload. For details, consult Completing the REST API Server. As usual, obtain this information from the API’s documentation to understand their requirements.
Let’s define the logic to send the HTTP POST requests in the cmd/client.go file. Edit this file and update the import section by including two new dependencies: the bytes package to use a buffer of bytes as the content ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access