A skill for using Copilot to generate API client code, SDK wrappers, and integration layers with proper error handling and retry logic.
## Copilot API Integration Skill
### Overview
Use Copilot to generate robust API client code with proper error handling, retry logic, and type-safe request/response handling.
### Method 1: From API Documentation
Describe the API endpoint and let Copilot generate the client:
```typescript
// Generate a typed API client for the Stripe Payments API
// POST /v1/charges
// Headers: Authorization: Bearer sk_test_xxx, Content-Type: application/x-www-form-urlencoded
// Body: amount (int, cents), currency (string), source (string)
// Response: Charge object with id, amount, status, created
async function createCharge(params: CreateChargeParams): Promise<Charge> {
// Copilot generates the complete implementation
}
```
### Method 2: SDK Wrapper Generation
Generate a complete API client class:
```
Generate a TypeScript API client class for a REST API with:
- Base URL configuration
- JWT authentication with automatic token refresh
- Request/response interceptors for logging
- Retry logic with exponential backoff (3 retries)
- Timeout configuration (30s default)
- Type-safe methods for: GET, POST, PUT, PATCH, DELETE
- Error handling that wraps HTTP errors in typed exceptions
```
### Method 3: From OpenAPI/Swagger Spec
```
@workspace Generate a TypeScript API client from the OpenAPI spec
at docs/openapi.yaml. Include:
- Interface for each schema definition
- Method for each endpoint with proper typing
- Request and response types
- JSDoc comments from API descriptions
```
### Robust Error Handling Pattern
```typescript
// Generate an API client with comprehensive error handling:
// - Network errors: retry with exponential backoff
// - 401: refresh token and retry once
// - 429: respect Retry-After header
// - 4xx: throw typed validation/not-found errors
// - 5xx: retry up to 3 times, then throw
// - Timeout: throw TimeoutError after 30s
```
### Rate Limiting and Throttling
```typescript
// Generate a rate-limited API client that:
// - Respects X-RateLimit-Remaining and X-RateLimit-Reset headers
// - Queues requests when approaching rate limit
// - Automatically backs off when rate limited
// - Supports concurrent request limits (max 10 in-flight)
```
### Webhook Handler Generation
```typescript
// Generate a webhook handler for Stripe events:
// - Verify webhook signature using signing secret
// - Parse event type and route to appropriate handler
// - Idempotency: skip already-processed events
// - Error handling: return 200 even on processing failure
// - Logging: log event type, id, and processing result
```
### Testing API Integrations
```
Generate tests for the PaymentClient:
- Mock HTTP responses for success and error cases
- Test retry logic with sequential failure then success
- Test token refresh on 401 response
- Test timeout handling
- Test rate limit handling with Retry-After header
- Use MSW (Mock Service Worker) for realistic HTTP mocking
```
### Tips
- Always generate types for request/response payloads
- Include retry logic for production API clients
- Handle all HTTP status codes, not just 200
- Add request/response logging for debugging
- Use dependency injection for the HTTP client to enable testingFree to copy and use. Compatible with GitHub Copilot, GPT-5.
Describe the API you need to integrate with in comments or Copilot Chat. Include endpoint URLs, auth method, and expected request/response shapes for best results.
Initial release
gh copilot skill install copilot-api-integration-client-skillSign in and download this prompt to leave a review.