Skip to main content
Jonas Weber·

Wrapped a raw REST API into a typed SDK with retries and backoff - shipped it same day

Creates a complete, developer-friendly SDK wrapper around a REST API or service with typed methods, error handling, and retry logic.

SDK Wrapper & Client Library Generator

You are an SDK engineer building a developer-friendly client library. Create a complete, production-ready wrapper. ## API Specification ``` {{api_specification}} ``` ## SDK Requirements - Target language: {{target_language}} - Package name: {{package_name}} - HTTP client: {{http_client_preference}} (axios, fetch, got, reqwest, etc.) - Auth method: {{auth_method}} - Minimum supported version: {{language_version}} ## SDK Structure (generate all) 1. **Main Client Class** - With: - Constructor accepting config (baseURL, auth, timeouts, retries) - Method for each API endpoint - Typed request/response interfaces - Configurable interceptors - Auto-pagination for list endpoints - Rate limit awareness (exponential backoff) 2. **Error Classes** - Custom error hierarchy matching API error codes 3. **Type Definitions** - Complete TypeScript types / type hints for all models 4. **Authentication Handler** - Token refresh, expiry handling 5. **Retry Logic** - Configurable retry with jitter, circuit breaker pattern 6. **Request/Response Logging** - Debug mode with sanitized output 7. **README** - Installation, quickstart, all methods documented 8. **Unit Tests** - Mocked HTTP tests for all endpoints 9. **Package Config** - package.json, setup.py, Cargo.toml, etc. Follow the SDK design guidelines of the target language ecosystem. Include JSDoc/docstrings for all public methods.

Ergebnisse

SDK wrapper around the Weatherstack REST API in TypeScript, package `@acme/weather-sdk`, using `fetch` with bearer auth. ```typescript // src/client.ts export interface WeatherConfig { apiKey: string; baseUrl?: string; maxRetries?: number; } export class WeatherClient { constructor(private cfg: WeatherConfig) { this.cfg.baseUrl ??= "https://api.weatherstack.com"; this.cfg.maxRetries ??= 3; } /** Current conditions for a city. */ async current(city: string): Promise<CurrentWeather> { return this.request<CurrentWeather>(`/current?query=${encodeURIComponent(city)}`); } private async request<T>(path: string, attempt = 1): Promise<T> { const res = await fetch(`${this.cfg.baseUrl}${path}`, { headers: { Authorization: `Bearer ${this.cfg.apiKey}` }, }); if (res.status === 429 && attempt <= this.cfg.maxRetries!) { const backoff = 2 ** attempt * 100 + Math.random() * 100; // jittered await new Promise((r) => setTimeout(r, backoff)); return this.request<T>(path, attempt + 1); } if (!res.ok) throw new WeatherApiError(res.status, await res.text()); return res.json() as Promise<T>; } } ``` **Includes:** `WeatherApiError` hierarchy, typed `CurrentWeather` model, exponential backoff with jitter, and a `quickstart` in the README. Vitest mocks for `current()` ship in `test/client.test.ts`.

Modell: Claude Sonnet 4

7 Likes3 SavesScore: 6

1 Kommentar

Luca Brunner·

The code generation details here are spot on.