Updated Jun 23, 2026

chi From Zero

chi is the framework for people who like net/http and only want the one thing the standard library doesn't give you: a real router. Its whole philosophy is stay compatible with the standard library. A chi handler is a plain http.HandlerFunc. chi middleware is a plain func(http.Handler) http.Handler. A chi router is an http.Handler. That means everything you learn in chi transfers straight to the broader Go ecosystem, and any stdlib-compatible middleware works with it unchanged. If Gin and Echo are "frameworks with their own context," chi is "the standard library, plus routing."

The mental model is one router built from standard pieces. The router (chi.NewRouter()) maps method

  • path to ordinary http.HandlerFuncs, supports URL parameters (/tasks/{id}) the stdlib mux long lacked, and lets you compose sub-routers and a middleware stack out of plain http.Handler wrappers. There's no special context value to learn — you use r *http.Request and w http.ResponseWriter like always, and pull URL params with chi.URLParam(r, "id").

📝 This teaches the framework — it assumes you know Go (Go From Zero) and the shape of net/http (a quick read of the net/http roots guide makes chi feel obvious). Compare it with Gin and Echo to see the "own-context" vs "stdlib-native" split. chi runs as a Go program, so examples are shown with the commands to run them.

How to read this

Read in order — it grows one service (a small articles API) using only net/http types plus chi's router. Phases carry difficulty badges.

The phases

  1. What chi Is 🟢 — the "just a router" philosophy and why staying net/http-compatible matters.
  2. Routing, URL Params & Sub-routers 🟢 — methods, {id} params, Route/Mount, and nested routers.
  3. Middleware the Standard Way 🟡 — func(http.Handler) http.Handler, chi's built-in middlewares, and per-route stacks.
  4. Requests & Responses with the Standard Library 🟡 — decoding JSON, writing JSON, status codes, and small helpers.
  5. Building a REST API 🟡 — full CRUD for the articles resource with chi + the stdlib.
  6. Structuring & Testing 🔴 — handlers/services layout, context values, and httptest.
  7. Where to Go Next 🟢 — chi vs Gin/Echo, the improved stdlib mux, and what to build.

The throughline: chi adds a router to the standard library and gets out of the way. Learn chi and you've mostly learned idiomatic net/http — which is exactly the point.


Phase 1: What chi Is →