Simplicity that
flows.
A modern, minimal Go toolkit for Chi, made for building great things.
A modern, minimal Go toolkit for Chi, made for building great things.
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.
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)
}func createUser(w http.ResponseWriter, r *http.Request) error {
var body CreateUserBody
if err := kori.BindJSON(r, &body); err != nil {
return err // 400 or 422, with structured details
}
user, err := db.Create(body.Name, body.Email)
if err != nil {
return kori.Conflict("email already in use")
}
return kori.JSON(w, http.StatusCreated, 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.
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.
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))The whole package fits on one screen. Full API reference
GET · POST · PUT · PATCH · DELETERegister handlers that return error on any chi.Router.BindJSON · BindQuery · BindPath · BindHeader · BindForm · BindMultipartDecode into a struct and validate it with go-playground/validator in one call.JSON · Text · NoContent · Redirect · RawJSONWrite the response and return its error on the same line.NotFound · BadRequest · Conflict · Unauthorized · NewErrorTyped HTTP errors with a single, replaceable error handler.Group · UsePrefixed sub-routers and per-route middleware.NewSSEWriter · SendJSON · PingServer-Sent Events for progress feeds and LLM tokens.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
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{}},
}))CreateUserBody:
type: object
required: [name, email]
properties:
name:
type: string
minLength: 2
email:
type: string
format: emailKori needs Go 1.26+ and Chi v5. Add it to an existing router and convert handlers at your own pace.