chi routes HTTP requests using a Patricia Radix trie — a compact prefix tree that delivers fast, allocation-efficient lookups even across thousands of routes. Every route you register is stored as a node in this tree, and at request time chi walks the tree once to find the best match, extract URL parameters, and invoke the correct handler. Because chi implements the standardDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/go-chi/chi/llms.txt
Use this file to discover all available pages before exploring further.
http.Handler interface throughout, every middleware package, test helper, and deployment tool that works with net/http works identically with chi.
The Router interface
chi’sRouter interface extends http.Handler with methods for registering routes, composing middleware, and building sub-routers. You get a concrete *Mux by calling chi.NewRouter().
main.go
HTTP method routing
chi provides a dedicated method for every standard HTTP verb. Each method accepts a URL pattern and anhttp.HandlerFunc.
routes.go
Dynamic method selection
When you need to select a method at runtime or register a handler that responds to every HTTP method, useHandle, HandleFunc, Method, or MethodFunc.
dynamic-methods.go
URL pattern syntax
All patterns must begin with/. chi supports four kinds of placeholders.
| Syntax | Name | Example | Matches |
|---|---|---|---|
{name} | Named param | /users/{userID} | Any sequence up to the next / |
{name:regexp} | Regex param | /{articleSlug:[a-z-]+} | Only characters matching the regexp |
{:regexp} | Anonymous regex | /v1/{:\d+}/data | Matches the regexp without capturing |
* | Wildcard | /files/* | Remainder of the path, including / |
Regular expressions use Go’s RE2 syntax. The
/ character is never matched by a regexp
placeholder — use the * wildcard if you need to match across path segments.Pattern examples
pattern-examples.go
Full articles example
The following example from the chi README shows named params, regex constraints, nested sub-routers, and middleware composition all working together.articles.go
Custom 404 and 405 handlers
chi lets you replace the defaulthttp.NotFound and 405 Method Not Allowed responses with your own handlers. Custom handlers propagate down to all sub-routers that don’t define their own.
custom-handlers.go
Patricia Radix trie internals
chi’s trie compresses common path prefixes so that/articles, /articles/search, and /articles/{id} share a single /articles prefix node. This keeps memory usage low and lookup time proportional to the length of the path rather than the total number of routes. URL parameters are captured during the trie walk and stored directly on the request context via context.WithValue, making them available through chi.URLParam(r, "key") from any point downstream in the handler chain.
URL Parameters
Read named params, regex captures, and wildcards from the request context.
Sub-Routers
Compose routes with
r.Route, r.Group, and r.With.Mounting
Attach any
http.Handler at a path prefix with r.Mount.