# Kotlin Ktor

> Ktor framework - routing, authentication, WebSockets

- Skill: `majiayu000/kotlin-ktor` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add majiayu000/kotlin-ktor`
- Raw SKILL.md: https://api.skillmd.com/api/skills/majiayu000/kotlin-ktor/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: majiayu000 (https://skillmd.com/u/majiayu000)
- Updated: 2026-09-09
- Page: https://skillmd.com/skills/majiayu000/kotlin-ktor

---


# Kotlin Ktor Skill

Build production-ready backends with Ktor.

## Topics Covered

### Routing
```kotlin
fun Application.module() {
    install(ContentNegotiation) { json() }
    routing {
        route("/api/v1") {
            get("/users") { call.respond(userService.findAll()) }
            get("/users/{id}") {
                val id = call.parameters["id"]?.toLongOrNull()
                    ?: throw BadRequestException("Invalid ID")
                call.respond(userService.findById(id) ?: throw NotFoundException())
            }
        }
    }
}
```

### JWT Authentication
```kotlin
install(Authentication) {
    jwt("auth") {
        verifier(JWT.require(Algorithm.HMAC256(secret)).build())
        validate { credential ->
            if (credential.payload.getClaim("userId").asString().isNotEmpty())
                UserPrincipal(credential.payload)
            else null
        }
    }
}

authenticate("auth") { userRoutes() }
```

### Testing
```kotlin
@Test
fun `GET users returns list`() = testApplication {
    application { module() }
    client.get("/api/v1/users").apply {
        assertThat(status).isEqualTo(HttpStatusCode.OK)
    }
}
```

## Troubleshooting

| Issue | Resolution |
|-------|------------|
| 404 for valid route | Order specific routes before wildcards |
| JSON not parsed | Install ContentNegotiation plugin |

## Usage
```
Skill("kotlin-ktor")
```

