Skip to main content

Documentation 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.

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 with 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: standard net/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’s context.Context — no global state is involved.
main.go
package main

import (
	"net/http"

	"github.com/go-chi/chi/v5"
	"github.com/go-chi/chi/v5/middleware"
)

func main() {
	r := chi.NewRouter()
	r.Use(middleware.Logger)
	r.Get("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte("welcome"))
	})
	http.ListenAndServe(":3000", r)
}

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 is github.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 the Router 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:
type Router interface {
    http.Handler
    Routes

    Use(middlewares ...func(http.Handler) http.Handler)
    With(middlewares ...func(http.Handler) http.Handler) Router
    Group(fn func(r Router)) Router
    Route(pattern string, fn func(r Router)) Router
    Mount(pattern string, h http.Handler)

    Handle(pattern string, h http.Handler)
    HandleFunc(pattern string, h http.HandlerFunc)
    Method(method, pattern string, h http.Handler)
    MethodFunc(method, pattern string, h http.HandlerFunc)

    // HTTP-method routing along `pattern`
    Connect(pattern string, h http.HandlerFunc)
    Delete(pattern string, h http.HandlerFunc)
    Get(pattern string, h http.HandlerFunc)
    Head(pattern string, h http.HandlerFunc)
    Options(pattern string, h http.HandlerFunc)
    Patch(pattern string, h http.HandlerFunc)
    Post(pattern string, h http.HandlerFunc)
    Put(pattern string, h http.HandlerFunc)
    Trace(pattern string, h http.HandlerFunc)

    NotFound(h http.HandlerFunc)
    MethodNotAllowed(h http.HandlerFunc)
}

Ecosystem packages

chi’s core is intentionally minimal. A collection of first-party optional packages under github.com/go-chi extends it for common needs:
PackageDescription
corsCross-origin resource sharing (CORS)
jwtauthJWT authentication
httprateHTTP request rate limiting
httplogStructured HTTP request logging
hostrouterDomain/host-based request routing
docgenAuto-generate routing docs from source
renderRequest/response payload management
The full source code, issue tracker, and contribution guide are on GitHub at https://github.com/go-chi/chi.

Build docs developers (and LLMs) love