Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Building a RESTful API – CR | Go Programming Bootcamp lesson | BraveProgrammer
  1. Courses
  2. /
  3. Go Programming Bootcamp

Lesson 21 of 60

·Go

Building a RESTful API – CRUD Operations

30 minutes

Course progress35%

A Minimal CRUD API

This lesson explains the main concept clearly with beginner-friendly examples and background so you can learn why the code works.

We will build a tiny in‑memory Todo API.

type Todo struct {
    ID   int    `json:"id"`
    Task string `json:"task"`
    Done    
}

 (
    store   = []Todo{}
    nextID  = 
    storeMu sync.RWMutex
)


 {
     t Todo
    json.NewDecoder(r.Body).Decode(&t)
    storeMu.Lock()
    t.ID = nextID
    nextID++
    store[t.ID] = t
    storeMu.Unlock()
    w.WriteHeader(http.StatusCreated)
    json.NewEncoder(w).Encode(t)
}


 {
    storeMu.RLock()
     storeMu.RUnlock()
     list []Todo
     _, v :=  store { list = (list, v) }
    json.NewEncoder(w).Encode(list)
}
bool
`json:"done"`
var
map
int
1
// Create
func createTodo(w http.ResponseWriter, r *http.Request)
var
// Read (list)
func listTodos(w http.ResponseWriter, r *http.Request)
defer
var
for
range
append

Register handlers with a router (http.ServeMux or chi).

Info

For production you’d replace the in‑memory map with a persistent DB and add proper validation.
Make it stickPractice what you've learned1 quiz · 3 practical tests · Optional activities from Go Programming BootcampBrowse activities
Previous lessonTemplate Rendering with `html/template`Continue to lesson 22Dependency Management with Go ModulesBack to Go Programming Bootcamp curriculum