chi is a lightweight, idiomatic, and composable router for building Go HTTP services. Built on a Patricia Radix trie, chi delivers fast URL matching with zero external dependencies — just the Go standard library. It is 100% compatible withDocumentation 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.
net/http, meaning any existing Go HTTP handler or middleware works with chi out of the box. Whether you are building a small microservice or a large REST API, chi scales with your project while keeping your codebase clean and maintainable.
Why chi?
chi was designed with a specific philosophy: standardnet/http handlers everywhere, composable middleware stacks, and a clean separation of routing concerns. The core router clocks in at under 1,000 lines of code, yet it delivers everything you need to structure a production-grade HTTP service.
Quickstart
Get a working chi HTTP service running in under five minutes.
Routing Overview
Learn URL patterns, named params, wildcards, and sub-routers.
Middleware Overview
Explore chi’s built-in middleware suite and how to compose your own.
REST API Guide
Walk through building a full RESTful API service with chi.
Key features
100% net/http Compatible
Use any
net/http-compatible handler or middleware package from the Go ecosystem — no adapters needed.Zero External Dependencies
chi depends only on the Go standard library. Your
go.mod stays clean.Composable Middleware
Stack, group, and inline middleware at any level of your router tree using
Use, With, Group, and Route.Context-based URL Params
URL parameters are stored on
context.Context and retrieved with chi.URLParam(r, "key") — no globals, no magic.Route Groups & Sub-routers
Organize routes with
r.Route(...) for inline groups and r.Mount(...) to attach fully independent sub-routers.Go Modules Support
Full Go module support since v5. Import as
github.com/go-chi/chi/v5.How chi works
chi’s router is built on a Patricia Radix trie, which enables efficient prefix-based route matching. Each node in the trie can carry its own middleware stack, so middleware scoped to a route group only runs for requests that match that group. URL parameters and wildcards are parsed at match time and attached to the request’scontext.Context — no global state is involved.
main.go
Current version
The current stable release is v5.0.12, released on 2024-02-16. chi v5 introduced Go module Semantic Import Versioning (SIV), so the import path isgithub.com/go-chi/chi/v5. chi tracks the four most recent major Go releases and requires Go 1.23 or later.
If you are upgrading from chi v4, only the import path changed — from
github.com/go-chi/chi to github.com/go-chi/chi/v5. The entire API is identical. See the Installation page for a step-by-step migration guide.Trusted in production
chi is battle-tested at scale. Organizations running chi in production include:- Cloudflare — global network services
- Heroku — platform-as-a-service infrastructure
- 99designs — creative services marketplace
The Router interface
Every chi router implements theRouter interface, which embeds http.Handler so it can be passed directly to http.ListenAndServe. The full interface covers HTTP-method routing, middleware composition, sub-router mounting, and custom NotFound/MethodNotAllowed handlers: