SDKs

Kotlin

Idiomatische Kotlin-Patterns für Android und JVM

Verwende OkHttp + kotlinx.serialization für JVM/Android oder Ktor für Coroutine-First-Stil. OkHttp wird unten gezeigt.

Gradle

dependencies {
    implementation("com.squareup.okhttp3:okhttp:4.12.0")
    implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}

Konfigurieren

import okhttp3.*
import kotlinx.serialization.json.Json

private const val API = "https://openapi.thunderbit.com/openapi/v1"
private val JSON_MEDIA = "application/json".toMediaType()
private val client = OkHttpClient()

private fun request(path: String) = Request.Builder()
    .url("$API$path")
    .header("Authorization", "Bearer ${System.getenv("THUNDERBIT_API_KEY")}")

Eine Seite distillen

val body = """{"url": "https://thunderbit.com/playground"}"""
    .toRequestBody(JSON_MEDIA)

client.newCall(request("/distill").post(body).build()).execute().use { res ->
    if (!res.isSuccessful) error("HTTP ${'$'}{res.code}")
    println(res.body!!.string())
}

Strukturierte Daten extrahieren

val body = """
{
  "url": "https://example.com/product/iphone-15-pro",
  "schema": {
    "type": "object",
    "properties": {
      "name":  { "type": "string" },
      "price": { "type": "number" }
    },
    "required": ["name", "price"]
  }
}
""".trimIndent().toRequestBody(JSON_MEDIA)

val res = client.newCall(request("/extract").post(body).build()).execute()

Coroutines + Batch

Für Android-UI-Arbeit packst du Aufrufe in withContext(Dispatchers.IO) oder verwendest Ktors Suspend-Client. Bei Batch-Jobs reichst du ein und wartest dann auf einen Webhook-Handler — siehe Webhooks.

Ein offizielles Kotlin SDK ist in Entwicklung — schau bald wieder rein.