SDK & Integrations

Android Kotlin Coroutines & Ktor Client

Kotlin suspend functions and JSON serialization for native Android apps.

Mobile App SDKs
Native Android Kotlin integration with Coroutines and Ktor/HttpURLConnection for Android apps.

Quick Start

Kotlin Coroutine BaziClient
Kotlin
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.net.HttpURLConnection
import java.net.URL

class BaziClient(private val apiKey: String) {
    suspend fun calculate(birthDate: String, birthTime: String, gender: String): String = withContext(Dispatchers.IO) {
        val url = URL("https://api.baziapi.pro/api/v1/bazi/calculate")
        val conn = url.openConnection() as HttpURLConnection
        conn.requestMethod = "POST"
        conn.setRequestProperty("x-api-key", apiKey)
        conn.setRequestProperty("Content-Type", "application/json")
        conn.doOutput = true

        val body = """{"birthDate":"$birthDate","birthTime":"$birthTime","gender":"$gender"}"""
        conn.outputStream.write(body.toByteArray())

        conn.inputStream.bufferedReader().readText()
    }
}

Something unclear? Contact developer support.