Simplicity that
flows.

A modern, minimal Go toolkit for Chi, made for building great things.

Get started

Same handler. Less noise.

Decoding, validating, choosing a status, setting Content-Type. Every Chi handler repeats it. Kori moves that work into helpers: handlers return errors, structs bind and validate in one call.

28 lines
func createUser(w http.ResponseWriter, r *http.Request) {
    var body CreateUserBody
    if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
        w.Header().Set("Content-Type", "application/json")
        w.WriteHeader(http.StatusBadRequest)
        json.NewEncoder(w).Encode(map[string]string{"message": "invalid JSON"})
        return
    }

    if err := validate.Struct(body); err != nil {
        w.Header().Set("Content-Type", "application/json")
        w.WriteHeader(http.StatusUnprocessableEntity)
        json.NewEncoder(w).Encode(map[string]string{"message": err.Error()})
        return
    }

    user, err := db.Create(body.Name, body.Email)
    if err != nil {
        w.Header().Set("Content-Type", "application/json")
        w.WriteHeader(http.StatusConflict)
        json.NewEncoder(w).Encode(map[string]string{"message": "email already in use"})
        return
    }

    w.Header().Set("Content-Type", "application/json")
    w.WriteHeader(http.StatusCreated)
    json.NewEncoder(w).Encode(user)
}

Invalid JSON returns 400. A failed validate tag returns 422 with field-level details. Any other error becomes a 500 that never leaks internals.

Chi stays in charge.

Kori is not a framework. It registers routes on your chi.Router, takes your middleware as is, and keeps http.ResponseWriter and *http.Request in every signature. Adopt it one handler at a time.

  • Standard Chi handlers and Kori handlers share one router
  • Any func(http.Handler) http.Handler works, per group or per route
  • No context wrapper, no custom request type, nothing to unlearn
main.go
r := chi.NewRouter()
r.Use(middleware.Logger)

// a plain Chi handler, untouched
r.Get("/health", func(w http.ResponseWriter, r *http.Request) {
    w.Write([]byte("ok"))
})

// Kori handlers on the same router
users := kori.Group(r, "/users", auth.Bearer(verify))
kori.GET(users, "/", listUsers)
kori.POST(users, "/", createUser)
kori.DELETE(users, "/{id}", deleteUser, kori.Use(requireAdmin))

A small surface you can hold in your head.

The whole package fits on one screen. Full API reference

Handlers
GET · POST · PUT · PATCH · DELETERegister handlers that return error on any chi.Router.
Binding
BindJSON · BindQuery · BindPath · BindHeader · BindForm · BindMultipartDecode into a struct and validate it with go-playground/validator in one call.
Responses
JSON · Text · NoContent · Redirect · RawJSONWrite the response and return its error on the same line.
Errors
NotFound · BadRequest · Conflict · Unauthorized · NewErrorTyped HTTP errors with a single, replaceable error handler.
Structure
Group · UsePrefixed sub-routers and per-route middleware.
Streaming
NewSSEWriter · SendJSON · PingServer-Sent Events for progress feeds and LLM tokens.

OpenAPI from the routes you already wrote.

The optional kori/openapi module reads the same json, path, query and validate tags you use for binding. Your structs become the spec. No annotations to keep in sync. Read the OpenAPI guide

users.go
type CreateUserBody struct {
    Name  string `json:"name"  validate:"required,min=2"`
    Email string `json:"email" validate:"required,email"`
}

kori.POST(r, "/users", createUser, spec.Route(openapi.RouteConfig{
    Summary:   "Create a user",
    Body:      &CreateUserBody{},
    Responses: map[int]any{201: &User{}},
}))
openapi.yaml
CreateUserBody:
  type: object
  required: [name, email]
  properties:
    name:
      type: string
      minLength: 2
    email:
      type: string
      format: email

Start with one handler.

Kori needs Go 1.26+ and Chi v5. Add it to an existing router and convert handlers at your own pace.

Read the docs