Recipe

Recipe: Ktor handler scaffold

Generate a complete Ktor route handler with validation, error mapping, and Meridian license check in one pass.

Scaffold

fun Route.meridianHandler(
    path: String,
    method: HttpMethod,
    body: suspend PipelineContext<Unit, ApplicationCall>.(call: ApplicationCall) -> Unit
) {
    route(path, method) {
        handle {
            val license = call.request.headers["X-Meridian-Key"]
                ?: throw LicenseMissingException()
            MeridianVerifier.verify(license)
            body(call)
        }
    }
}

Validation

Request body deserialization with kotlinx.serialization and automatic 422 responses on failure.

Error mapping

StatusPages plugin wired to map LicenseException → 403, ValidationException → 422.

Meridian — getnimbus.net