Skip to content

HTTP client examples ​

Example http_request component calls for common API integration patterns. See HTTP client component for the full configuration reference.

Fetch data and process ​

yaml
# ~/.kdeps/config.yaml
http_connections:
  github:
    auth:
      type: bearer
      token: "${GITHUB_TOKEN}"

# resources/fetch-data.yaml
actionId: fetchData
component:
  name: http_request
  with:
    method: GET
    url: "https://api.github.com/repos/{{ get('owner') }}/{{ get('repo') }}"
    headers:
      Accept: application/vnd.github.v3+json
    connectionName: github
    timeout: 30s

---

actionId: analyzeRepo
flow:
  requires: [fetchData]
chat:
  model:
    name: llama3.2:1b
  context:
    prompt: "Analyze this GitHub repo: {{ get('fetchData') }}"

Authenticated API with retry ​

yaml
# ~/.kdeps/config.yaml
http_connections:
  stripe:
    auth:
      type: bearer
      token: "${STRIPE_SECRET_KEY}"

# resources/example.yaml
component:
  name: http_request
  with:
    method: POST
    url: "https://api.stripe.com/v1/charges"
    connectionName: stripe
    headers:
      Content-Type: application/x-www-form-urlencoded
    data:
      amount: "{{ get('amount') }}"
      currency: usd
      source: "{{ get('token') }}"
    retry:
      maxAttempts: 3
      backoff: 2s
      retryOn: [500, 502, 503]
    timeout: 30s

Webhook call ​

yaml
# resources/example.yaml
component:
  name: http_request
  with:
    method: POST
    url: "{{ get('webhook_url') }}"
    headers:
      Content-Type: application/json
      X-Webhook-Secret: "{{ get('WEBHOOK_SECRET', 'env') }}"
    data:
      event: order_completed
      order_id: "{{ get('order_id') }}"
      timestamp: "{{ info('timestamp') }}"
    timeout: 10s

Cached external API ​

yaml
# resources/example.yaml
component:
  name: http_request
  with:
    method: GET
    url: "https://api.exchangerate.host/latest"
    cache:
      ttl: 1h
      key: "exchange-rates"
    timeout: 30s

See also ​

kdeps has the Apache 2.0 License.