Goal: Build a minimal REST API with chi to lock in routing, JSON decoding, and error handling — all from memory.
To install, use:
curl -fsSL https://github.com/egeuysall/notes-api/master/install.sh | sh
Method | Route | Description |
---|---|---|
GET | /ping |
Returns { "message": "pong" } |
POST | /note |
Accepts { "text": "..." } , returns ID |
GET | /note/{id} |
Returns note by ID or 404 |
- Use:
chi
,json.NewDecoder
,json.NewEncoder
,http.Error
,chi.URLParam
- Store data in:
map[string]string
- Generate random ID (e.g.
6-char
string)
- Write
main.go
withchi.NewRouter
- Create
GET /ping
route - Respond with JSON manually:
json.NewEncoder(w).Encode(...)
- Set correct headers/status codes
- Add
POST /note
- Decode JSON body into struct
- Generate random ID
- Store in map
- Respond with ID in JSON
- Add
GET /note/{id}
- Get param with
chi.URLParam
- Lookup in map, return value or 404
- Get param with
- Add
DELETE /note/{id}
- Get param with
chi.URLParam
- Check if note exists
- Delete from map
- Return 204 No Content
- Get param with
- Build the Notes CLI
- Flags package
- error handling
- Publish via Goreleaser
- Configure Goreleaser
- Clean up code structure (handlers, error messages)
- Write a reflection note in Obsidian:
- What did I remember easily?
- What did I forget?
- Any confusing areas?
- Save code to
~/go-snippets/notes-api