REST patterns for this codebase — both the Ktor server routes and outgoing HTTP clients. Detailed examples live in the sub-files — load them on demand.
Quick reference
Server-side (incoming requests)
Concept
Implementation
Route definition
Extension functions on Route (fun Route.myApi(...))
Route mounting
Inside authenticate(providerName) { ... } block in RoutingConfig
Serialization
kotlinx.serialization with @Serializable data classes
1---2name: navikt-sokos-skattekort-ktor-rest-api3description: Ktor REST API4---56# Ktor REST API78REST patterns for this codebase — both the Ktor server routes and outgoing HTTP clients. Detailed examples live in the sub-files — load them on demand.910## Quick reference1112### Server-side (incoming requests)1314| Concept | Implementation |15|---|---|16| Route definition | Extension functions on `Route` (`fun Route.myApi(...)`) |17| Route mounting | Inside `authenticate(providerName) { ... }` block in `RoutingConfig` |18| Serialization | `kotlinx.serialization` with `@Serializable` data classes |19| Request validation | `RequestValidation` plugin with `validate<T>` blocks |20| Error responses | `StatusPages` plugin mapping exceptions → `ApiError` JSON |21| Access control | `call.requirePermission()` / `requireScope()` / `requireRole()` per endpoint |22| Swagger | `swaggerUI()` per API version, backed by OpenAPI YAML specs in `resources/openapi/` |23| API versioning | Path-based: `/api/v1/...`, `/api/v2/...` |24| JSON config | Shared `jsonConfig` (`prettyPrint`, `ignoreUnknownKeys`, `encodeDefaults`, `explicitNulls = false`) |2526### Client-side (outgoing requests)2728| Concept | Implementation |29|---|---|30| HTTP engine | Ktor `HttpClient(Apache5)` with proxy and keep-alive |31| Resilience | Resilience4j `CircuitBreaker` wrapping suspend functions |32| Retry | Ktor `HttpRequestRetry` plugin with exponential backoff |33| Auth | `bearerAuth()` with Azure AD or Maskinporten tokens |34| Content negotiation | `ContentNegotiation` with `kotlinx.serialization` JSON |35| Named dependencies | `@Named("clientName")` for URL and token client injection |3637## Sub-files3839- [server-routes.md](server-routes.md) — route extension functions, DTOs, request validation, Swagger UI40- [http-client.md](http-client.md) — HttpClient config, circuit breaker, token auth, retry41- [error-handling.md](error-handling.md) — StatusPages, ApiError, exception-to-HTTP mapping4243## Boundaries4445### Always46- Extension functions on `Route` for API definitions — never inline routes in `Application.module()`47- `@Serializable` data classes for request/response bodies48- Shared `jsonConfig` for consistent JSON behavior across server and client49- `StatusPages` for centralized error handling — never catch-and-respond in individual routes50- Circuit breaker on every outgoing HTTP client51- Bearer auth via `AzuredTokenClient` (M2M) or `MaskinportenTokenClient` (external)52- OpenAPI YAML specs in `src/main/resources/openapi/` — Swagger UI is auto-mounted53- Access control on every authenticated endpoint5455### Never56- Return raw exceptions to the client — always go through `StatusPages`57- Build HTTP clients without retry and circuit breaker58- Use `expectSuccess = true` on clients where non-2xx is a valid business response59- Hardcode URLs — always inject via `@Named` string constants from `PropertiesConfig`60- Skip access control on authenticated routes6162---63> Source: [navikt/sokos-skattekort](https://github.com/navikt/sokos-skattekort) — distributed by [TomeVault](https://tomevault.io).64<!-- tomevault:4.0:skill_md:2026-06-15 -->
Run npx skillmds@latest add tomevault-io/navikt-sokos-skattekort-ktor-rest-api in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Ktor REST API It is listed under Integrations & APIs on SkillMD.
This skill has not completed SkillMD's automated safety review yet. Independent scanners report: SkillSpector: PASS, Skill Scanner: PASS. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
tomevault-io (@tomevault-io) published this skill. Their other Agent Skills are listed on their SkillMD profile.