Skip to main content

SHOWCASE_05_API_TESTER

Constant SHOWCASE_05_API_TESTER 

Source
pub const SHOWCASE_05_API_TESTER: &str = r##"# ═══════════════════════════════════════════════════════════════════
# Pattern 05: API Endpoint Tester
# ═══════════════════════════════════════════════════════════════════
#
# Test multiple API endpoints with full response inspection.
# Demonstrates: for_each + fetch response:full + structured report.
#
# Prerequisites: None (public endpoints)
# Run: nika run workflows/showcase/05-api-tester.nika.yaml

schema: "nika/workflow@0.12"
workflow: api-endpoint-tester
description: "Test API endpoints and report structured results"

provider: "{{PROVIDER}}"
model: "{{MODEL}}"

tasks:
  - id: test_endpoints
    for_each:
      - "https://httpbin.org/get"
      - "https://httpbin.org/ip"
      - "https://httpbin.org/uuid"
      - "https://httpbin.org/user-agent"
      - "https://httpbin.org/headers"
      - "https://httpbin.org/delay/1"
    as: endpoint
    concurrency: 3
    fail_fast: false
    fetch:
      url: "{{with.endpoint}}"
      method: GET
      response: full
      timeout: 10

  - id: analyze_results
    depends_on: [test_endpoints]
    with:
      raw_results: $test_endpoints
    structured:
      schema:
        type: object
        properties:
          total_endpoints:
            type: integer
          healthy_count:
            type: integer
          slow_count:
            type: integer
            description: "Endpoints with response time > 2 seconds"
          summary:
            type: string
            description: "Brief health summary"
        required: [total_endpoints, healthy_count, slow_count, summary]
    infer:
      prompt: |
        Analyze these API test results and produce a health report.
        Count total endpoints, healthy ones (2xx), and slow ones (>2s).

        Results: {{with.raw_results}}
      temperature: 0.1
"##;