android-kmp-ktor-serializationlisted
Install: claude install-skill lenorebreakneck630/claude-zero-to-hero-android-KMP
# KMP Ktor + kotlinx.serialization
## Dependency setup
```toml
# libs.versions.toml
[versions]
ktor = "2.3.12"
serialization = "1.7.3"
[libraries]
ktor-client-core = { module = "io.ktor:ktor-client-core", version.ref = "ktor" }
ktor-client-content-negotiation = { module = "io.ktor:ktor-client-content-negotiation", version.ref = "ktor" }
ktor-serialization-json = { module = "io.ktor:ktor-serialization-kotlinx-json", version.ref = "ktor" }
ktor-client-logging = { module = "io.ktor:ktor-client-logging", version.ref = "ktor" }
ktor-client-okhttp = { module = "io.ktor:ktor-client-okhttp", version.ref = "ktor" }
ktor-client-darwin = { module = "io.ktor:ktor-client-darwin", version.ref = "ktor" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "serialization" }
```
## HttpClient factory (`commonMain`)
```kotlin
// core:data — commonMain
fun createHttpClient(engine: HttpClientEngine): HttpClient = HttpClient(engine) {
install(ContentNegotiation) {
json(Json {
ignoreUnknownKeys = true
isLenient = true
})
}
install(Logging) {
level = LogLevel.HEADERS
}
defaultRequest {
url("https://api.example.com/v1/")
contentType(ContentType.Application.Json)
}
}
```
## Platform engine injection
```kotlin
// androidMain
fun provideHttpClient(): HttpClient = createHttpClient(OkHttp.create())
// iosMain
fun provideHttpClient(): HttpClient = createHttp