SDKs

Elixir

Idiomatische Elixir-Patterns für Phoenix und OTP

Verwende Req (den modernen Elixir-HTTP-Client) — basiert auf Finch und bringt Retries und Connection Pooling von Haus aus mit.

mix.exs

defp deps do
  [
    {:req, "~> 0.5"}
  ]
end

Konfigurieren

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

Eine Seite distillen

def distill(url) do
  client()
  |> Req.post!(url: "/distill", json: %{url: url})
  |> Map.fetch!(:body)
  |> get_in(["data", "markdown"])
end

Strukturierte Daten extrahieren

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"]
})

Batch mit Oban

Für asynchrones Fan-out stellst du Submissions mit Oban in die Queue und lässt deinen Phoenix-Endpoint den Webhook-Callback verarbeiten:

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")
    }
  })
end

Verifiziere die Webhook-Signatur in deinem Phoenix-Controller — siehe Webhooks.

Ein offizielles Elixir SDK ist in Entwicklung — schau bald wieder rein.