API Fetch Wrapper

Referenz-TypeScript-Muster zum Wrappen einer externen HTTP API: env secrets, bounded retry

von ChronoAIProject · ChronoAIProject/Ornn

Getestet · Funktioniert ★ 8.8/10

API Fetch Wrapper — Referenz-TypeScript-Muster zum Wrappen einer externen HTTP API: env secrets, bounded retry

Was es kann

Ein runnable TypeScript example that wraps a public HTTP API (keyless Open-Meteo demo) with env-based credential handling, one bounded retry on transient failures, und error normalisation that never echoes the upstream body. Wird ausgelöst, wenn Sie einen skill oder client build möchten, that calls an external service with proper retry und secret hygiene. Reuse the retry/error skeleton und swap the URL plus process.env key for an authed API.

Testbericht

Führte den gebündelten code live against the real Open-Meteo endpoint aus: happy path returned 16.5C / 17.4 km/h, malformed input produced a structured {error} with exit 1, und an unreachable host triggered the retry (a 500ms delay was observed in wall time) then returned {error,cause} with no upstream body leaked. Against a naive baseline wrapper it adds three non-obvious touches an average implementation skips: no-leak-on-failure error mapping, draining the response body for socket reuse, und a deliberate transient-only (408/429/5xx) retry filter. The example ist small but every claim in its frontmatter held up under execution.

Getestet am: 2026-07-20 · Claude Code 2.x (agent harness)

Installation

git clone https://github.com/ChronoAIProject/Ornn
mkdir -p ~/.claude/skills
cd Ornn && cp -r examples/api-fetch-wrapper ~/.claude/skills/api-fetch-wrapper

Befehle & Beispiel-Prompts

  • /api-fetch-wrapperReferenz-TypeScript-Muster zum Wrappen einer externen HTTP API: env secrets, bounded retry

Skills reagieren auf normale Anfragen — keine Slash-Befehle nötig. Nach der Installation aktivieren Prompts wie diese den Skill (auf Englisch):

  • Show me a TypeScript pattern for wrapping an external API safely
  • Build a fetch wrapper with bounded retry and no leaked error bodies
  • Wrap this authed API client with env secrets and retry logic