An opinionated Ktor-based HTTP client wrapped by MoonServerClient,
with built-in retry, exponential backoff, and typed error surface via
MoonServerException.
- Kotlin 2.0.20, Compose Multiplatform 1.7.x, AGP 8.6.x, Gradle 8.10, Java 21.
- A reachable backend (the MoonDeveloper backend, or your own).
- Valid
moonLicenseKey. - Koin 4.1.0.
(Same repository block as auth/en.md §2.)
implementation("io.moondeveloper:moon-server-kmp:1.0.0")INTERNETpermission (standard, present in the sample manifest).
- No special capability needed; the module bundles the Ktor Darwin engine.
import io.moondev.server.moonServerModule
startKoin {
modules(moonServerModule /*, ... */)
}MoonServerClient becomes available from any Koin scope.
class HealthStore(private val client: MoonServerClient) {
suspend fun ping(): String =
try {
client.get("/health")
} catch (e: MoonServerException) {
"down: ${e.code} ${e.message}"
}
}@Composable
fun ServerScreen(store: HealthStore = koinInject()) {
val scope = rememberCoroutineScope()
var result by remember { mutableStateOf("") }
Button(onClick = { scope.launch { result = store.ping() } }) { Text("Ping") }
Text(result)
}MoonServerException(code=401)on every call — check the auth token interceptor (the module pulls the token fromAuthProviderif both are wired).- Timeouts on slow networks — raise the per-request timeout via the client's configuration hook; the default is conservative.
- iOS "URLSessionTask suspended" logs — usually a background-mode conflict; see Apple docs on app-lifecycle + URLSession.
- Wrap in a feature-specific repository to hide the raw path strings.
- See
ServerCallScreen.kt.