SDKs
Elixir
Phoenix와 OTP를 위한 Elixir의 관용적인 패턴
Req(현대적인 Elixir HTTP 클라이언트) 를 사용하세요 —— Finch 위에 구축되어 있으며 retry 와 connection pooling 을 기본 제공합니다.
mix.exs
defp deps do
[
{:req, "~> 0.5"}
]
end설정
defmodule Thunderbit do
@api "https://openapi.thunderbit.com/openapi/v1"
defp client do
Req.new(
base_url: @api,
auth: {:bearer, System.fetch_env!("THUNDERBIT_API_KEY")},
receive_timeout: 60_000
)
end
end페이지 Distill
def distill(url) do
client()
|> Req.post!(url: "/distill", json: %{url: url})
|> Map.fetch!(:body)
|> get_in(["data", "markdown"])
end구조화된 데이터 Extract
def extract(url, schema) do
client()
|> Req.post!(url: "/extract", json: %{url: url, schema: schema})
|> Map.fetch!(:body)
|> Map.fetch!("data")
end
extract("https://example.com/product/iphone-15-pro", %{
type: "object",
properties: %{
name: %{type: "string"},
price: %{type: "number"}
},
required: ["name", "price"]
})Oban 으로 Batch 처리
비동기 분산 처리를 위해 Oban 으로 제출 작업을 큐에 넣고, Phoenix 엔드포인트가 Webhook 콜백을 처리하도록 하세요.
def submit_batch(urls) do
client()
|> Req.post!(url: "/batch/distill", json: %{
urls: urls,
webhook: %{
url: "#{MyApp.Endpoint.url()}/webhooks/distill",
secret: System.fetch_env!("WEBHOOK_SECRET")
}
})
endPhoenix 컨트롤러에서 Webhook 시그니처를 검증하세요 —— Webhooks 를 참고하세요.
공식 Elixir SDK 가 개발 중입니다 —— 곧 다시 확인해 주세요.