kotlin-ktorlisted
Install: claude install-skill Mixard/fable-pack
# Ktor 3.x Server Patterns
Ktor apps are configured as `Application` extension functions installing plugins, with routes as `Route` extension functions. Keep routes thin; push logic to services injected via Koin.
## Entry point and module
```kotlin
fun main() {
embeddedServer(Netty, port = 8080, module = Application::module).start(wait = true)
}
fun Application.module() {
configureSerialization()
configureAuthentication()
configureStatusPages()
configureCORS()
configureDI()
configureRouting()
}
```
## Routing DSL
```kotlin
fun Application.configureRouting() {
routing {
userRoutes()
authRoutes()
}
}
fun Route.userRoutes() {
val userService by inject<UserService>() // Koin
route("/users") {
get { call.respond(userService.getAll()) }
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>()
call.respond(HttpStatusCode.Created, userService.create(request))
}
delete("/{id}") {
val id = call.parameters["id"]
?: return@delete call.respond(HttpStatusCode.BadRequest, "Missing id")
if (userService.delete(id)) call.respond(