kotlin-ktor-patterns

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

Updated May 7, 2026
One-click install
npx skills add https://github.com/mirzadham/trainingroombookingsystem2 --skill kotlin-ktor-patterns-mirzadham
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: kotlin-ktor-patterns
Source: https://github.com/mirzadham/trainingroombookingsystem2/tree/main/.pi/skills/kotlin-ktor-patterns
Command: npx skills add https://github.com/mirzadham/trainingroombookingsystem2 --skill kotlin-ktor-patterns-mirzadham

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Building a Ktor HTTP server requires wiring together many plugins, routing conventions, serialization rules, and authentication layers, and getting these patterns wrong leads to inconsistent APIs and fragile error handling. ## Core Features & Use Cases - Routing and Plugin Patterns: Standard project layout with route grouping, ContentNegotiation, StatusPages error handling, and CORS configuration. - JWT Authentication and Koin DI: JWT setup with token validation, protected route scoping, and Koin module definitions for services and repositories. - Testing and WebSockets: testApplication integration tests for public and authenticated routes, plus WebSocket connection management. - Use Case: When scaffolding a new Kotlin REST API, apply these patterns to get consistent JSON responses, centralized exception mapping, and testable route handlers from day one. ## Quick Start Use the kotlin-ktor-patterns skill to scaffold a Ktor server with JWT authentication, Koin dependency injection, and integration tests.

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 the credential payload. Wrap protected routes in an authenticate("jwt") block and extract claims via JWTPrincipal.

How to structure routes in a Ktor application?▼

Define routes as extension functions on Route in separate files, then register them inside a central configureRouting function. Group endpoints with route("/path") blocks and separate public routes from authenticated ones using the authenticate block.

Does Ktor support dependency injection with Koin?▼

Yes, install the Koin plugin in your Application module and register modules containing singletons for repositories and services. Access dependencies inside route handlers using the by inject<T>() delegate.

How do I test Ktor routes with testApplication?▼

Use the testApplication block, configure your application modules inside it, and create a client with ContentNegotiation installed. Send requests with client.get or client.post and assert on response status and deserialized bodies.

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

Without the StatusPages plugin, unhandled exceptions produce default HTML error pages. Install StatusPages and register exception handlers for specific types like IllegalArgumentException and Throwable to return structured JSON error responses.