Intermediate

Build a REST API in Go

Stand up a JSON API with routing, middleware, and graceful shutdown using nothing but net/http and the standard library.

~6h
0 / 6 steps
🚀
Intro

Before We Start

Prerequisites: Concurrency with Goroutines and Channels; basic familiarity with HTTP and JSON.

Version note: verified against current docs as of July 2026, targeting the common Go 1.25/1.26 feature set.

Go 1.22 added method- and wildcard-based routing directly to net/http's ServeMux (things like mux.HandleFunc("GET /items/{id}", handler)), which closed most of the gap that used to justify reaching for a third-party router for simple APIs. This project builds a small in-memory "items" REST API — list, get, create, delete — with middleware for logging, and a graceful shutdown that finishes in-flight requests before exiting.

🔨

Route with the standard library mux

🔨

Encode and decode JSON cleanly

🔨

Add middleware for logging and recovery, then shut down gracefully

🎯
Secret Mission

Secret Mission: Add request validation and pagination

🧹
Wrap Up

Before You Go

Pro

Test what you just learned

Self-testing is one of the best ways to retain new skills. Unlock project quizzes to check your understanding.

Log in to unlock