SDKs
Java
Idiomatische Java-Patterns für die Thunderbit Open API
Verwende java.net.http.HttpClient (eingebaut, Java 11+). Für mehr Komfort — Connection Pooling, Retries — kombinierst du OkHttp + Jackson.
Konfigurieren
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;
private static final String API = "https://openapi.thunderbit.com/openapi/v1";
private static final HttpClient CLIENT = HttpClient.newBuilder()
.connectTimeout(Duration.ofSeconds(10))
.build();
private static HttpRequest.Builder request(String path) {
return HttpRequest.newBuilder()
.uri(URI.create(API + path))
.header("Authorization", "Bearer " + System.getenv("THUNDERBIT_API_KEY"))
.header("Content-Type", "application/json")
.timeout(Duration.ofSeconds(60));
}Eine Seite distillen
String body = "{\"url\":\"https://thunderbit.com/playground\"}";
HttpResponse<String> res = CLIENT.send(
request("/distill").POST(HttpRequest.BodyPublishers.ofString(body)).build(),
HttpResponse.BodyHandlers.ofString()
);
if (res.statusCode() >= 400) throw new RuntimeException(res.body());Strukturierte Daten extrahieren
String body = """
{
"url": "https://example.com/product/iphone-15-pro",
"schema": {
"type": "object",
"properties": {
"name": { "type": "string" },
"price": { "type": "number" }
},
"required": ["name", "price"]
}
}
""";
HttpResponse<String> res = CLIENT.send(
request("/extract").POST(HttpRequest.BodyPublishers.ofString(body)).build(),
HttpResponse.BodyHandlers.ofString()
);Parse die Response mit Jackson oder Gson in deinen Domain-Typ.
Batch + Webhook
String body = """
{
"urls": ["https://example.com/page1", "https://example.com/page2"],
"webhook": {
"url": "https://your-server.com/webhook",
"secret": "%s"
}
}
""".formatted(System.getenv("WEBHOOK_SECRET"));
HttpResponse<String> res = CLIENT.send(
request("/batch/distill").POST(HttpRequest.BodyPublishers.ofString(body)).build(),
HttpResponse.BodyHandlers.ofString()
);Verifiziere die Webhook-Signatur in deinem Handler — siehe Webhooks.
Ein offizielles Java SDK ist in Entwicklung — schau bald wieder rein.