API Reference

generateKotlinClient

Generate a native Kotlin client from a Kizuna API with OkHttp, kotlinx.serialization, and coroutines.

Beta

The Kotlin client is new and still settling. The generated API surface may change while v2 is in beta, so pin your version if you depend on it.

Generate a native Kotlin client from your routes. The generated client uses OkHttp for HTTP, kotlinx.serialization for JSON, and Kotlin coroutines for async.

pnpm add @kizunajs/kotlin@beta
bun add @kizunajs/kotlin@beta
npm install @kizunajs/kotlin@beta
import { generateKotlinClient } from '@kizunajs/kotlin';

Parameters

generateKotlinClient(api: ApiDefinition, config: KotlinConfig): string
ParameterTypeDescription
apiApiDefinitionThe api from defineConfig
configKotlinConfigGeneration configuration

KotlinConfig

OptionTypeRequiredDescription
namespaceNamestringYesName for the generated object and client class (e.g. 'API')
packageNamestringNoPackage declaration for the generated file (e.g. 'com.example.api')
camelCasePropertiesbooleanNoConvert wire field names to camelCase properties, mapped back via @SerialName. Default false
unknownEnumCasebooleanNoEmit enums as a sealed interface with an Unknown(wireValue) member so unrecognised wire values decode instead of throwing. Default false

Example

generate-kotlin.ts
import path from 'path';
import { writeFileSync } from 'fs';
import { generateKotlinClient } from '@kizunajs/kotlin';
import kizuna from '../kizuna.config';

const kotlin = generateKotlinClient(kizuna.api, {
    namespaceName: 'API',
    packageName: 'com.example.api',
});

writeFileSync('generated/APIClient.kt', kotlin);

See the Kotlin client guide for CLI usage and integration patterns.

On this page