SDKs
Kotlin
Idiomatische Kotlin-patronen voor Android en JVM
Gebruik OkHttp + kotlinx.serialization voor JVM/Android, of Ktor voor coroutine-first stijl. OkHttp wordt hieronder getoond.
Gradle
dependencies {
implementation("com.squareup.okhttp3:okhttp:4.12.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.7.3")
}Configureren
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")}")Een pagina 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())
}Gestructureerde data Extracten
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
Voor Android UI-werk wikkel je calls in withContext(Dispatchers.IO) of gebruik je Ktor's suspend-client. Voor batch jobs submit je en wacht je op een Webhook handler — zie Webhooks.
Een officiële Kotlin SDK is in ontwikkeling — kom binnenkort terug.