Api integration

From Hack23/riksdagsmonitor · View interactive version

Api integration is an AI agent skill from the GitHub repository Hack23/riksdagsmonitor. REST/GraphQL API client design, rate limiting, error handling, and authentication best practices

How to use this skill

Skill file

API Integration Skill

🔴 AI FIRST Quality Principle

Apply the AI FIRST principle: never accept first-pass quality. Minimum 2 iterations. Read all output, improve every section. No shortcuts.

Purpose

Expert knowledge in building robust API clients with proper error handling, rate limiting, authentication, and retry logic.

Core Principles

  1. Resilience - Handle failures gracefully
  2. Rate Limiting - Respect API limits
  3. Retry Logic - Exponential backoff
  4. Circuit Breaker - Fail fast when needed
  5. Security - Secure credential storage

Enforces

API Client Pattern

class APIClient {
  constructor(config) {
    this.baseUrl = config.baseUrl;
    this.timeout = config.timeout || 30000;
    this.retries = config.retries || 3;
    this.circuitBreaker = new CircuitBreaker();
  }
  
  async request(endpoint, options = {}) {
    if (this.circuitBreaker.isOpen()) {
      throw new Error('Circuit breaker open');
    }
    
    for (let attempt = 1; attempt <= this.retries; attempt++) {
      try {
        const response = await fetch(
          `${this.baseUrl}${endpoint}`,
          { ...options, timeout: this.timeout }
        );
        
        if (!response.ok) {
          throw new APIError(response.status, response.statusText);
        }
        
        this.circuitBreaker.recordSuccess();
        return await response.json();
      } catch (error) {
        if (attempt === this.retries) {
          this.circuitBreaker.recordFailure();
          throw error;
        }
        await this.delay(1000 * Math.pow(2, attempt));
      }
    }
  }
}

When to Use

References


Version: 1.0 | Last Updated: 2026-02-06 | Category: Development & Operations

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.