kotlin-ktor-patterns

Create Ktor HTTP servers with routing, JWT authentication, and Koin DI.

1|Updated Mar 18, 2026
One-click install
npx skills add https://github.com/xxih/ai-harness-zh --skill kotlin-ktor-patterns-xxih
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: kotlin-ktor-patterns
Source: https://github.com/xxih/ai-harness-zh/tree/main/references/translations/everything-claude-code/docs/zh-CN/skills/kotlin-ktor-patterns
Command: npx skills add https://github.com/xxih/ai-harness-zh --skill kotlin-ktor-patterns-xxih

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It helps developers quickly set up a full‑featured Ktor HTTP server, handling routing, authentication, dependency injection, serialization, CORS, error handling, WebSockets, and automated testing, eliminating the need to assemble boilerplate from multiple sources.

Core Features & Use Cases

  • Routing DSL: Define clean, modular routes with nested groups.
  • Authentication: JWT‑based auth plugin integrated with Ktor.
  • Dependency Injection: Koin modules for services and repositories.
  • Content Negotiation: kotlinx.serialization for JSON payloads.
  • CORS & Status Pages: Secure cross‑origin requests and unified error handling.
  • WebSocket support: Real‑time communication endpoints.
  • testApplication testing: End‑to‑end integration tests for routes and auth. Use case example: building a microservice that exposes REST APIs with secure JWT auth, uses a PostgreSQL repository via Koin, and provides real‑time chat via WebSockets.

Quick Start

Ask the skill to generate a basic Ktor project skeleton with routing, JWT authentication, and Koin DI configured.

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 a Ktor server with JWT authentication and Koin dependency injection?

You can set up a Ktor server with JWT and Koin by configuring the auth plugin for token validation and defining Koin modules for repositories. This combination secures REST APIs while maintaining modular service layers.

What is the best way to structure routing and content negotiation in a Kotlin microservice?

The best way to structure routing and content negotiation in a Kotlin microservice is using Ktor's routing DSL for nested route groups and kotlinx.serialization for JSON payloads. This eliminates boilerplate when building REST APIs.

Does Ktor support WebSockets and CORS for real-time microservice communication?

Ktor supports WebSockets for real-time communication endpoints and CORS for secure cross-origin requests. These plugins integrate directly into routing to handle real-time chat and secure browser interactions.

How do I write integration tests for a Ktor HTTP server with JWT auth?

You write integration tests for a Ktor HTTP server with JWT auth using the testApplication function. This allows you to perform end-to-end testing of routes and authentication flows without deploying the full server.

Can I use kotlinx.serialization for JSON handling in a Ktor REST API?

Yes, you can use kotlinx.serialization for JSON handling in a Ktor REST API through the content negotiation plugin. It automatically serializes and deserializes JSON payloads for your HTTP endpoints.