kotlin-ktor-patterns

Implements Ktor server patterns for routing, authentication, dependency injection, and testing.

1|Updated Oct 11, 2025
One-click install
npx skills add https://github.com/ibytechaos/claude --skill kotlin-ktor-patterns-ibytechaos
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-ktor-patterns
Source: https://github.com/ibytechaos/claude/tree/main/plugins/everything-claude-code/skills/kotlin-ktor-patterns
Command: npx skills add https://github.com/ibytechaos/claude --skill kotlin-ktor-patterns-ibytechaos

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building a Ktor HTTP server involves wiring together many plugins—routing, serialization, JWT authentication, CORS, error handling, and dependency injection—and getting the configuration right is error-prone without proven patterns. ## Core Features & Use Cases - Routing & Plugin Setup: Provides standard patterns for the routing DSL, ContentNegotiation with kotlinx.serialization, StatusPages error handling, and CORS configuration. - JWT Authentication & Koin DI: Shows how to configure JWT auth with protected routes and wire services and repositories through Koin modules. - Integration Testing: Demonstrates testApplication-based tests, including authenticated route testing with generated JWTs. - Use Case: When scaffolding a new Kotlin REST API, apply these patterns to set up authenticated CRUD endpoints with consistent error responses and full test coverage. ## Quick Start Ask the AI to scaffold a Ktor server with JWT authentication, Koin dependency injection, and testApplication integration tests for a users REST API.

Frequently Asked Questions about kotlin-ktor-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I set up JWT authentication in a Ktor server?

Install the Authentication plugin with a jwt provider, configure a verifier using HMAC256 with your secret, issuer, and audience, then validate credentials and return a JWTPrincipal. Protect routes by wrapping them in an authenticate("jwt") block.

How to structure a Ktor project with routing and services?

Use a standard layout with plugins/ for configuration functions, routes/ for endpoint definitions, services/ for business logic, and repositories/ for data access. Keep routes thin by injecting services via Koin and pushing logic downward.

How do I test Ktor routes with testApplication?

Wrap tests in a testApplication block, install your modules and plugins inside the application block, then use the built-in client to make requests. For JSON bodies, create a client with ContentNegotiation installed and assert on response status and deserialized bodies.

Does Ktor support dependency injection with Koin?

Yes, install the Koin plugin in your Application module and register modules defining repositories and services as singles. Routes access dependencies with the by inject<T>() delegate, and tests can override bindings with mock modules.

Why does my Ktor server return 500 instead of a structured error?

Unhandled exceptions bypass your response format unless you install the StatusPages plugin. Register exception handlers for specific types like IllegalArgumentException and a fallback Throwable handler that logs the error and returns a consistent ApiResponse error body.