Chi
By go-chi contributors
Chi is a lightweight, idiomatic HTTP router for the Go programming language, built entirely on Go's standard `net/http` package without introducing a custom router interface or non-standard handler signatures. It supports URL parameter…
Definition
Chi is a lightweight, idiomatic HTTP router for the Go programming language, built entirely on Go's standard `net/http` package without introducing a custom router interface or non-standard handler signatures. It supports URL parameter capture, middleware chaining, route grouping, and sub-routing while remaining a small, dependency-free library rather than a full framework. Chi is used by Go developers who want expressive routing on top of the standard library's HTTP server rather than adopting a heavier, more opinionated web framework.
Overview
Chi was created in response to a recurring frustration among Go developers: the standard library's `net/http.ServeMux` router supports only basic path matching and lacks features like path parameters, middleware composition, or route grouping that most real applications need. Rather than build a new framework with its own request and response abstractions, Chi's authors chose to implement these features as a thin layer directly on top of the standard `http.Handler` interface, so that any Chi route or middleware is also a valid, ordinary Go HTTP handler. Mechanically, Chi organizes routes in a radix trie, a tree structure optimized for matching URL path segments quickly even as the number of registered routes grows, and it exposes URL parameters captured from the path through Go's `context.Context` rather than a custom request wrapper. Middleware in Chi is simply a function that takes an `http.Handler` and returns another `http.Handler`, the same pattern used throughout the Go standard library and countless third-party tools, which means Chi middleware can be mixed freely with middleware written for `net/http` directly. Route groups and sub-routers let a codebase apply middleware, like authentication or logging, to a subset of routes without repeating registration code. Chi's closest competitor is Gorilla Mux, another router built on `net/http`; the two differ mainly in performance characteristics and API surface, with Chi's radix-trie matching generally outperforming Mux's regular-expression-based matching at scale, and Chi favoring a smaller, more composable middleware model. Compared with full frameworks like Gin, Echo, or Buffalo, Chi deliberately does nothing beyond routing and middleware composition — there is no built-in templating, ORM, or validation layer, leaving those choices entirely to the application. In practice, Chi is a common choice for building REST APIs and microservices in Go where a team wants full control over the rest of their stack — logging, validation, database access — while still getting expressive routing with URL parameters and grouped middleware. Its adherence to standard `net/http` types also means it integrates cleanly with Go's built-in testing tools, standard middleware from other libraries, and observability instrumentation that expects ordinary `http.Handler` values. The trade-off for this minimalism is that a team must assemble its own conventions for request validation, response serialization, and error handling, which a more opinionated framework would provide out of the box. Chi's ongoing maintenance has also depended on a small number of active contributors, so teams evaluating it for long-term production use should check current release activity, though its stable, standard-library-based design means existing Chi applications rarely need to change even if new releases slow down.
Key Features
- Router built entirely on Go's standard net/http interfaces
- Radix-trie based route matching for efficient URL dispatch
- URL parameter extraction via Go's standard context.Context
- Middleware expressed as plain http.Handler wrapping functions
- Route groups and sub-routers for scoped middleware application
- Zero non-standard-library dependencies in its core package
- Compatible with middleware written for plain net/http
- Built-in helpers for common patterns like URL parameter validation