FAQ
Global path prefix
Put every route under /api (or any prefix).
The question: How do I serve all my routes under /api, but keep /health at the root?
app.http(adapter) { setGlobalPrefix("/api", exclude = listOf("/health", "/metrics")) }GET /users becomes GET /api/users; the excluded paths (and everything below them) stay where they are. With versioning the prefix comes first: /api/v1/users.
| Declared | Served as |
|---|---|
@Controller("/users") | /api/users |
@Controller("/health") (excluded) | /health |
a route under a router module at /admin | /api/admin/... |
Why use a prefix
- One address for API and front end (
/api/...is Kest, everything else is your website: see Next.js). - A reverse proxy can route
/apito Kest by path alone. - It keeps API URLs distinct from pages.
Things to remember
- The documentation site (
/docs) and other mounted endpoints (/metrics) follow the same rule: list them inexcludeif they should stay at the root (or let them move under the prefix). - Clients, health probes and monitoring must use the new URLs: update load balancer checks (
/healthexcluded above keeps them working). - Set it once, at start-up, in the
http { }block.