English for Chi Router Developers
Learn the English vocabulary for Chi, Go's lightweight HTTP router: middleware chains, route groups, and context values.
Chi’s minimalist design means discussions rely on a small, precise vocabulary — middleware chain, route group, context value — and getting these terms exactly right matters because Chi deliberately avoids the “magic” of heavier frameworks.
Key Vocabulary
Middleware chain — the ordered sequence of handler-wrapping functions applied to a request before it reaches the final route handler, executed in the order they were registered. “Move the auth middleware earlier in the chain — right now logging runs first and records requests that get rejected downstream anyway.”
Route group — a way of scoping a set of routes and middleware together under a shared prefix or condition, using r.Route() or r.Group(), without duplicating configuration per route.
“Put all the admin endpoints in their own route group so the admin-only middleware only wraps those routes, not the entire API.”
Context value — data passed through a request’s context.Context, commonly used in Chi to carry things like authenticated user information from middleware down to handlers.
“The handler’s panicking because it’s reading a context value that was never set — check whether the middleware that sets it actually ran first.”
URL parameter — a named, dynamic segment of a route path, like {id} in /users/{id}, retrievable in a handler via chi.URLParam().
“Don’t parse the URL manually — Chi already gives you the URL parameter directly, so just call chi.URLParam(r, "id").”
Mux — Chi’s core router object, short for multiplexer, responsible for matching incoming requests to the correct handler based on method and path. “Mount that sub-router onto the main mux instead of duplicating the routes — it’s the same pattern Chi uses for composing APIs from smaller pieces.”
Common Phrases
- “Where does this middleware sit in the chain — before or after authentication runs?”
- “Should this be its own route group, or is it small enough to stay with the main routes?”
- “Is this context value actually being set upstream, or is the handler reading something that was never populated?”
- “Are we using Chi’s URL parameter helper, or parsing the path manually somewhere?”
- “Is this mounted on the main mux, or is it still a separate, unconnected router?”
Example Sentences
Debugging a middleware ordering issue: “The rate limiter’s letting unauthenticated requests through because it’s running before the auth middleware in the chain — reorder them so auth happens first.”
Explaining an architecture choice: “We split the API into route groups by permission level, so the admin middleware only wraps the group of routes that actually need it.”
Reviewing a pull request: “This handler’s parsing the ID out of the raw URL string — use Chi’s URL parameter helper instead, it’s already doing the matching for you.”
Professional Tips
- Say middleware chain when discussing execution order — Chi’s behavior is entirely order-dependent, and naming it precisely helps diagnose bugs where request handling happens in the wrong sequence.
- Use route group rather than “section” or “block” when describing how routes and middleware are scoped together — it’s Chi’s actual mechanism for that scoping.
- Reference context value specifically when debugging data passed between middleware and handlers — it clarifies that the issue is about
context.Context, not global state. - Call the router a mux in conversation with other Go developers — it’s the conventional term and signals familiarity with Go’s
net/httpecosystem, not just Chi specifically.
Practice Exercise
- Explain why middleware order in the chain matters, using an authentication example.
- Describe what a route group is and when you’d use one.
- Write a sentence explaining how a context value gets from middleware into a handler.