Skip to content

chi

A small, standard-library-compatible router for building Go HTTP and REST API services.

Stars
23k
Forks
2.3k
Licence
MIT
Language
Go
Last update
19 days ago
Type
Library

What it is

chi is a routing library for Go that maps incoming web requests to the code that should handle them, such as sending /articles/123 to a function that loads article 123. It is built on Go's standard net/http package and context package, so handlers and middleware written for the standard library generally work with it. It is aimed at larger REST API projects that need to stay organized as they grow.

  • Define REST routes such as GET /articles and GET /articles/{articleID} with URL parameters
  • Group routes under shared middleware, for example an admin section that requires permission checks
  • Mount a separate router at a path prefix like /admin
  • Add request logging, request IDs, panic recovery, and timeouts with the optional middleware package
  • Generate routing documentation in JSON or Markdown with the docgen package

Great for

  • Go developers building REST API services
  • Teams that want routing built on the standard net/http package
  • Projects that need route groups, nested sub-routers, or mounted handlers
  • Developers who want optional middleware and route documentation generation

Not ideal for

  • Developers who want a full web framework with templates, ORM, and built-in auth, since chi covers routing and relies on separate packages for other needs
  • People not writing Go, since the library is Go-only
  • Beginners with no Go experience, since the README assumes familiarity with Go handlers and context
Step-by-step guide: how to use chiInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: Go (version not specified in the README)

    Install chi v5

    go get -u github.com/go-chi/chi/v5
  2. 2

    Run it

    • Install Go and run the install command above in your project folder
    • Create a main.go file with the example from the README that calls chi.NewRouter() and registers a GET route
    • Run the program with go run main.go
    • Open http://localhost:3000 in a browser to see the welcome response
  3. 3

    Get the most out of it

    • Add the middleware package for logging, request IDs, recovery, and timeouts, as shown in the README's REST preview
    • Use route groups and r.Route to nest resource-specific routes and shared middleware
    • Use r.Mount to attach a separate sub-router, such as an admin API
    • Use the docgen package to produce route documentation from your source
    • Check the _examples folder in the repository for working examples of features

Downloads

Strengths

  • Small core router (the README says under 1000 lines of code) with no external dependencies
  • Compatible with net/http, so existing standard-library handlers and middleware can be reused
  • Supports route groups, sub-routers, and mounting for organizing large APIs

Trade-offs

  • Routing only; features like rendering, validation, and database access need separate packages or your own code
  • The README's examples use string keys for context values, which is a pattern the README itself shows and not a fully type-safe approach

How it compares

ProjectStarsTypeLevelUpdatedBest for
chi (this)23kLibraryintermediate19 days agoGo developers building REST API services
gin89.5kLibraryintermediate27 days agoGo developers building REST APIs
echo32.8kLibraryintermediate6 days agoGo developers building REST APIs or backend services
kratos26kLibraryintermediate4 days agoGo developers building a set of backend services that talk over HTTP or gRPC
go-zero33.4kLibraryintermediate5 days agoGo developers building REST APIs or microservices
kit27.4kLibraryadvanced2.3 years agoGo developers building service-oriented or microservice backends

Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.