Learn practical Kotlin Ktor server patterns for building and testing backend apps.
Copy the install command and let the AI configure it · recommended for beginners
Please install the "kotlin-ktor-patterns" skill from askskill: 1. Download https://raw.githubusercontent.com/affaan-m/ECC/main/skills/kotlin-ktor-patterns/SKILL.md 2. Save it as ~/.claude/skills/kotlin-ktor-patterns/SKILL.md 3. Reload skills and tell me it's ready
Design a routing structure for a medium-sized REST API in Kotlin Ktor with users, orders, and auth modules. Use the routing DSL for grouping, and provide a recommended project folder structure with sample code.
A modular routing plan, recommended folder structure, and reusable Ktor routing sample code.
Give me a Ktor server example that integrates JWT authentication, Koin dependency injection, and kotlinx.serialization. Explain how each plugin is configured and show complete code for a login endpoint and a protected endpoint.
A complete example with configuration notes covering auth flow, DI registration, serialization setup, and endpoint implementation.
Use Ktor's testApplication to write tests for an authenticated API. Cover successful login, unauthorized access, and invalid parameter validation, and explain best practices for the test structure.
Executable Ktor test code plus recommendations for test layering and assertion design.
Comprehensive Ktor patterns for building robust, maintainable HTTP servers with Kotlin coroutines.
src/main/kotlin/
├── com/example/
│ ├── Application.kt # Entry point, module configuration
│ ├── plugins/
│ │ ├── Routing.kt # Route definitions
│ │ ├── Serialization.kt # Content negotiation setup
│ │ ├── Authentication.kt # Auth configuration
│ │ ├── StatusPages.kt # Error handling
│ │ └── CORS.kt # CORS configuration
│ ├── routes/
│ │ ├── UserRoutes.kt # /users endpoints
│ │ ├── AuthRoutes.kt # /auth endpoints
│ │ └── HealthRoutes.kt # /health endpoints
│ ├── models/
│ │ ├── User.kt # Domain models
│ │ └── ApiResponse.kt # Response envelopes
│ ├── services/
│ │ ├── UserService.kt # Business logic
│ │ └── AuthService.kt # Auth logic
│ ├── repositories/
│ │ ├── UserRepository.kt # Data access interface
│ │ └── ExposedUserRepository.kt
│ └── di/
│ └── AppModule.kt # Koin modules
src/test/kotlin/
├── com/example/
│ ├── routes/
│ │ └── UserRoutesTest.kt
│ └── services/
│ └── UserServiceTest.kt
// Application.kt
fun main() {
embeddedServer(Netty, port = 8080, module = Application::module).start(wait = true)
}
fun Application.module() {
configureSerialization()
configureAuthentication()
configureStatusPages()
configureCORS()
configureDI()
configureRouting()
}
// plugins/Routing.kt
fun Application.configureRouting() {
routing {
userRoutes()
authRoutes()
healthRoutes()
}
}
// routes/UserRoutes.kt
fun Route.userRoutes() {
val userService by inject<UserService>()
route("/users") {
get {
val users = userService.getAll()
call.respond(users)
}
get("/{id}") {
val id = call.parameters["id"]
?: return@get call.respond(HttpStatusCode.BadRequest, "Missing id")
val user = userService.getById(id)
?: return@get call.respond(HttpStatusCode.NotFound)
call.respond(user)
}
post {
val request = call.receive<CreateUserRequest>()
val user = userService.create(request)
call.respond(HttpStatusCode.Created, user)
}
put("/{id}") {
val id = call.parameters["id"]
?: return@put call.respond(HttpStatusCode.BadRequest, "Missing id")
val request = call.receive<UpdateUserRequest>()
val user = userService.update(id, request)
?: return@put call.respond(HttpStatusCode.NotFound)
call.respond(user)
}
delete("/{id}") {
val id = call.parameters["id"]
?: return@delete call.respond(HttpStatusCode.BadRequest, "Missing id")
val deleted = userService.delete(id)
if (deleted) call.respond(HttpStatusCode.NoContent)
else call.respond(HttpStatusCode.NotFound)
}
}
}
fun Route.userRoutes() {
route("/users") {
// Public routes
get { /* list users */ }
get("/{id}") { /* get user */ }
// Protected routes
authenticate("jwt") {
post { /* create user - requires auth */ }
put("/{id}") { /* update user - requires auth */ }
…
Handle returns, refunds, fraud checks, and warranty claim decisions efficiently.
Use Bun for runtime, bundling, testing, packages, and Node migration decisions.
Use the correct Ethereum Keccak-256 hashing in Node.js and TypeScript.
Apply Nuxt 4 patterns for SSR safety, performance, and data fetching.
Generate images, videos, and audio with one unified AI media workflow.
Design Quarkus 3 backend patterns for messaging, APIs, data, and async workflows.
Apply idiomatic Kotlin patterns to build robust, efficient, maintainable applications.
Learn practical Kotlin Coroutines and Flow patterns for Android and KMP.
Build high-quality Kotlin tests with Kotest, MockK, coroutines, and coverage.
Design and improve Spring Boot backend architecture, APIs, and service implementation.
Build HTTP service patterns with lifecycle hooks, WebSockets, SSE, and proxying.
Learn Kotlin conventions, result handling, and session patterns for DAT SDK Android.