Routing
Kori registers routes on any chi.Router. Every registration function follows the same shape:
kori.METHOD(router, pattern, handler, ...options)The router is always explicit — Kori never holds a global reference to it.
HTTP methods
Section titled “HTTP methods”kori.GET(r, "/users", listUsers)kori.POST(r, "/users", createUser)kori.PUT(r, "/users/{id}", replaceUser)kori.PATCH(r, "/users/{id}", updateUser)kori.DELETE(r, "/users/{id}", deleteUser)kori.HEAD(r, "/users/{id}", headUser)kori.OPTIONS(r, "/users", optionsUsers)Route parameters
Section titled “Route parameters”Chi’s {param} syntax is used in patterns. Read them with chi.URLParam:
func getUser(w http.ResponseWriter, r *http.Request) error { id := chi.URLParam(r, "id") // use id... return kori.JSON(w, http.StatusOK, user)}When there are multiple parameters or you need validation, use kori.BindPath instead:
type PostParams struct { UserID string `path:"user_id" validate:"required,uuid4"` PostID string `path:"post_id" validate:"required,uuid4"`}
func getPost(w http.ResponseWriter, r *http.Request) error { var p PostParams if err := kori.BindPath(r, &p); err != nil { return err } // p.UserID, p.PostID return kori.JSON(w, http.StatusOK, post)}Route groups
Section titled “Route groups”kori.Group creates a sub-router with a shared prefix. Middleware passed to Group applies to every route in the group.
// Prefix onlyapi := kori.Group(r, "/api/v1")kori.GET(api, "/users", listUsers)kori.POST(api, "/users", createUser)
// Prefix + middlewareadmin := kori.Group(r, "/admin", authMiddleware, auditMiddleware)kori.GET(admin, "/stats", statsHandler)kori.DELETE(admin, "/users/{id}", deleteUser)Groups nest:
api := kori.Group(r, "/api")v2 := kori.Group(api, "/v2") // prefix: /api/v2kori.GET(v2, "/users", listUsersV2)Per-route middleware
Section titled “Per-route middleware”Use kori.Use(...) to attach middleware to a single route without creating a sub-router:
kori.DELETE(r, "/admin/users/{id}", deleteUser, kori.Use(authMiddleware, auditMiddleware),)Multiple options compose naturally:
kori.POST(r, "/payments", createPayment, kori.Use(authMiddleware), kori.Use(idempotencyMiddleware),)Mixing with plain Chi
Section titled “Mixing with plain Chi”Standard Chi handlers and Kori handlers coexist on the same router:
r := chi.NewRouter()r.Use(middleware.Logger)
// plain Chi — no error returnr.Get("/health", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok"))})
// Kori handlerskori.GET(r, "/users", listUsers)kori.POST(r, "/users", createUser)