SDKs
Swift
Idiomatic Swift patterns for iOS and macOS apps
Use the built-in URLSession + Codable. async/await throughout. Targets iOS 15+, macOS 12+.
Configure
import Foundation
let api = URL(string: "https://openapi.thunderbit.com/openapi/v1")!
let apiKey = ProcessInfo.processInfo.environment["THUNDERBIT_API_KEY"]!
func request(path: String, body: Data? = nil) -> URLRequest {
var req = URLRequest(url: api.appendingPathComponent(path))
req.httpMethod = body == nil ? "GET" : "POST"
req.httpBody = body
req.timeoutInterval = 60
req.setValue("Bearer \(apiKey)", forHTTPHeaderField: "Authorization")
req.setValue("application/json", forHTTPHeaderField: "Content-Type")
return req
}Distill a page
struct DistillBody: Encodable { let url: String }
struct DistillResponse: Decodable {
struct Data: Decodable { let markdown: String }
let data: Data
}
let body = try JSONEncoder().encode(DistillBody(url: "https://thunderbit.com/playground"))
let (data, _) = try await URLSession.shared.data(for: request(path: "distill", body: body))
let result = try JSONDecoder().decode(DistillResponse.self, from: data)
print(result.data.markdown)Extract structured data
struct Product: Decodable { let name: String; let price: Double }
struct ExtractResponse: Decodable { let data: Product }
let payload: [String: Any] = [
"url": "https://example.com/product/iphone-15-pro",
"schema": [
"type": "object",
"properties": [
"name": ["type": "string"],
"price": ["type": "number"]
],
"required": ["name", "price"]
]
]
let body = try JSONSerialization.data(withJSONObject: payload)
let (data, _) = try await URLSession.shared.data(for: request(path: "extract", body: body))
let product = try JSONDecoder().decode(ExtractResponse.self, from: data).dataBatch + webhook
Submit and let your server-side webhook handler do the heavy lifting — most iOS apps shouldn't poll. See Webhooks.
An official Swift SDK is in development — check back soon.