Skip to content

DilanCalvo/task-manager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Task Manager API

A small REST API to manage tasks. Written in Go with the standard library only (no external frameworks).

What it does

Create tasks, list them, read one, update one, and delete one. Each task has a title, a description, a done flag, and a creation date.

This is my first Go project. I built it to learn the language by hand instead of following a tutorial. It practices:

  • HTTP routing and handlers with net/http
  • Reading and writing JSON with encoding/json
  • Structs, methods, and pointer receivers
  • Safe access to shared data with sync.Mutex
  • Go error handling (errors are returned as values, not thrown)

Tasks are kept in memory only. When you stop the server, all tasks are gone. This is on purpose: the goal is to learn Go, not to set up a database.

How it works

A request flows through three layers, each in its own package:

main.go  →  handlers/  →  store/  →  models/
(routing)   (HTTP code)   (data)     (Task type)
  • main.go creates the store and the handler, registers the routes, and starts the server on port 8080.
  • handlers/ reads the request, calls the store, and writes the JSON answer.
  • store/ keeps the tasks in a map and uses a mutex so many requests at the same time are safe.
  • models/ defines the Task type.

Project structure

task-manager/
├── go.mod
├── main.go              # wires everything together and starts the server
├── models/
│   └── task.go          # the Task struct
├── store/
│   └── store.go         # in-memory storage, protected by a mutex
└── handlers/
    └── task.go          # one HTTP handler per operation

Requirements

  • Go 1.22 or newer (the routing uses patterns like GET /tasks/{id}, which were added in Go 1.22).

Run

From the project folder:

go run .

You should see:

Task Manager API listening on :8080

The server now runs at http://localhost:8080. Keep this terminal open and use another one to send requests.

Endpoints

Method Path Description Success status
GET /tasks List all tasks 200
POST /tasks Create a new task 201
GET /tasks/{id} Get one task by ID 200
PUT /tasks/{id} Update a task by ID 200
DELETE /tasks/{id} Delete a task by ID 204

A task looks like this:

{
  "id": 1,
  "title": "Learn Go",
  "description": "Build a REST API",
  "done": false,
  "created_at": "2026-06-13T10:00:00Z"
}

Test it

Make sure the server is running in another terminal first.

macOS / Linux / Git Bash

# create
curl -X POST http://localhost:8080/tasks -H "Content-Type: application/json" -d '{"title":"Learn Go","description":"Build a REST API"}'
# list
curl http://localhost:8080/tasks
# get one
curl http://localhost:8080/tasks/1
# update
curl -X PUT http://localhost:8080/tasks/1 -H "Content-Type: application/json" -d '{"title":"Learn Go","description":"Done!","done":true}'
# delete
curl -X DELETE http://localhost:8080/tasks/1

Windows (PowerShell)

In PowerShell, curl is not the real curl, so use Invoke-RestMethod:

# create
Invoke-RestMethod -Uri http://localhost:8080/tasks -Method Post -ContentType "application/json" -Body '{"title":"Learn Go","description":"Build a REST API"}'
# list
Invoke-RestMethod -Uri http://localhost:8080/tasks
# get one
Invoke-RestMethod -Uri http://localhost:8080/tasks/1
# update
Invoke-RestMethod -Uri http://localhost:8080/tasks/1 -Method Put -ContentType "application/json" -Body '{"title":"Learn Go","description":"Done!","done":true}'
# delete
Invoke-RestMethod -Uri http://localhost:8080/tasks/1 -Method Delete

About

Small REST API CRUD wrotten in Go with the learn pourpose

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages