SDKs
.NET / C#
Thunderbit Open API를 위한 .NET의 관용적인 패턴
내장 HttpClient + System.Text.Json 을 사용하세요. 전반적으로 async/await. .NET 6+ 를 대상으로 합니다.
설정
using System.Net.Http.Json;
using System.Text.Json;
const string Api = "https://openapi.thunderbit.com/openapi/v1";
var client = new HttpClient
{
BaseAddress = new Uri(Api + "/"),
Timeout = TimeSpan.FromSeconds(60),
};
client.DefaultRequestHeaders.Authorization =
new("Bearer", Environment.GetEnvironmentVariable("THUNDERBIT_API_KEY"));페이지 Distill
var res = await client.PostAsJsonAsync("distill", new {
url = "https://thunderbit.com/playground"
});
res.EnsureSuccessStatusCode();
var json = await res.Content.ReadFromJsonAsync<JsonElement>();
Console.WriteLine(json.GetProperty("data").GetProperty("markdown").GetString());구조화된 데이터 Extract
record Product(string Name, decimal Price, string? Currency);
var res = await client.PostAsJsonAsync("extract", new {
url = "https://example.com/product/iphone-15-pro",
schema = new {
type = "object",
properties = new {
name = new { type = "string" },
price = new { type = "number" },
},
required = new[] { "name", "price" },
}
});
var body = await res.Content.ReadFromJsonAsync<JsonElement>();
var product = body.GetProperty("data").Deserialize<Product>(
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });Batch + Webhook
var job = await client.PostAsJsonAsync("batch/distill", new {
urls = new[] { "https://example.com/page1", "https://example.com/page2" },
webhook = new {
url = "https://your-server.com/webhook",
secret = Environment.GetEnvironmentVariable("WEBHOOK_SECRET"),
}
});
var body = await job.Content.ReadFromJsonAsync<JsonElement>();
var jobId = body.GetProperty("data").GetProperty("id").GetString();핸들러에서 Webhook 시그니처를 검증하세요 —— Webhooks 를 참고하세요.
공식 .NET SDK 가 개발 중입니다 —— 곧 다시 확인해 주세요.