Token导航 LogoToken导航TokenDH.com
开发external-servicegithub未标认证来源可访问许可证需确认审计通过

api-integrationAPI 集成

Agent Skill

用于辅助 API 设计、接口文档、请求响应结构和服务集成说明。它适合让 Agent 梳理 endpoint、生成 OpenAPI 草稿、检查字段命名、整理错误码或辅助前后端联调。使用时需要确认真实业务语义、鉴权方式、分页和错误处理规则;涉及生成接口文档时,应避免凭空补字段,最好从现有代码、schema 或接口样例中提取事实。

总安装

256

周安装

11

GitHub Stars

219

下载量

90
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:api-integration(API 集成)
来源仓库:https://github.com/hack23/cia
仓库路径:skills/api-integration
安装命令:
npx skills add https://github.com/hack23/cia --skill api-integration
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/hack23/cia --skill api-integration

简介

api-integration 用于辅助 API 设计、接口文档和请求响应结构整理。

  • 适用于梳理 endpoint、生成 OpenAPI 草稿和检查字段命名。
  • 确认业务语义、鉴权方式和错误处理规则后进行接口设计。
  • 安装命令:npx skills add https://github.com/hack23/cia --skill api-integration。
  • 避免凭空补字段,最好从现有代码或接口样例中提取事实。

SKILL.md

API Integration Skill

Purpose

Provide robust patterns for integrating the CIA platform with external government data APIs, including the Swedish Riksdagen, Election Authority, World Bank, and ESV (Swedish Financial Management Authority). Covers resilience, caching, and error handling.

When to Use

  • ✅ Integrating new external data sources
  • ✅ Improving reliability of existing API connections
  • ✅ Implementing caching for frequently accessed political data
  • ✅ Adding rate limiting to respect API provider constraints
  • ✅ Debugging API integration failures

Do NOT use for:

  • ❌ Internal service-to-service calls (use Spring patterns directly)
  • ❌ Database access patterns (use JPA/Hibernate skill)

CIA External API Landscape

APIBase URLData TypeRate Limit
Riksdagen Open Datadata.riksdagen.seParliament data, votes, documentsBest effort
Swedish Election Authoritydata.val.seElection results, partiesLow volume
World Bank Open Dataapi.worldbank.orgEconomic indicators50 req/sec
ESVwww.esv.seGovernment financesBest effort

Retry Logic Pattern

Exponential Backoff with Jitter

@Service
public class ResilientApiClient {

    private static final int MAX_RETRIES = 3;
    private static final long BASE_DELAY_MS = 1000;
    private static final Logger LOG = LoggerFactory.getLogger(ResilientApiClient.class);

    public <T> T executeWithRetry(Supplier<T> apiCall, String operationName) {
        int attempt = 0;
        while (true) {
            try {
                return apiCall.get();
            } catch (Exception e) {
                attempt++;
                if (attempt >= MAX_RETRIES || !isRetryable(e)) {
                    LOG.error("API call failed after {} attempts: {}", attempt, operationName, e);
                    throw new ApiIntegrationException(operationName, e);
                }
                long delay = calculateBackoff(attempt);
                LOG.warn("Retry {}/{} for {} after {}ms", attempt, MAX_RETRIES, operationName, delay);
                try {
                    Thread.sleep(delay);
                } catch (InterruptedException ie) {
                    Thread.currentThread().interrupt();
                    throw new ApiIntegrationException(operationName, ie);
                }
            }
        }
    }

    private long calculateBackoff(int attempt) {
        long exponentialDelay = BASE_DELAY_MS * (1L << (attempt - 1));
        long jitter = ThreadLocalRandom.current().nextLong(0, exponentialDelay / 2);
        return Math.min(exponentialDelay + jitter, 30_000);
    }

    private boolean isRetryable(Exception e) {
        if (e instanceof HttpClientErrorException httpErr) {
            int status = httpErr.getStatusCode().value();
            return status == 429 || status >= 500;
        }
        return e instanceof ResourceAccessException
            || e instanceof SocketTimeoutException;
    }
}

Circuit Breaker Pattern

@Component
public class CircuitBreaker {

    private enum State { CLOSED, OPEN, HALF_OPEN }

    private State state = State.CLOSED;
    private int failureCount = 0;
    private long lastFailureTime = 0;

    private static final int FAILURE_THRESHOLD = 5;
    private static final long RECOVERY_TIMEOUT_MS = 60_000;

    public synchronized <T> T execute(Supplier<T> action, Supplier<T> fallback) {
        if (state == State.OPEN) {
            if (System.currentTimeMillis() - lastFailureTime > RECOVERY_TIMEOUT_MS) {
                state = State.HALF_OPEN;
            } else {
                return fallback.get();
            }
        }

        try {
            T result = action.get();
            reset();
            return result;
        } catch (Exception e) {
            recordFailure();
            return fallback.get();
        }
    }

    private synchronized void recordFailure() {
        failureCount++;
        lastFailureTime = System.currentTimeMillis();
        if (failureCount >= FAILURE_THRESHOLD) {
            state = State.OPEN;
        }
    }

    private synchronized void reset() {
        failureCount = 0;
        state = State.CLOSED;
    }
}

Caching Strategy

Spring Cache Configuration

@Configuration
@EnableCaching
public class ApiCacheConfig {

    @Bean
    public CacheManager cacheManager() {
        CaffeineCacheManager manager = new CaffeineCacheManager();
        manager.setCaffeine(Caffeine.newBuilder()
            .maximumSize(10_000)
            .expireAfterWrite(Duration.ofHours(1))
            .recordStats());
        return manager;
    }
}

@Service
public class RiksdagDataService {

    @Cacheable(value = "politicians", key = "#personId")
    public PoliticianData getPolitician(String personId) {
        return riksdagClient.fetchPerson(personId);
    }

    @CacheEvict(value = "politicians", allEntries = true)
    @Scheduled(cron = "0 0 2 * * *") // Refresh at 2 AM daily
    public void evictPoliticianCache() {
        LOG.info("Evicting politician cache for daily refresh");
    }
}

Cache TTL Guidelines

Data TypeTTLReason
Politician profiles24 hoursChanges infrequently
Voting records1 hourUpdated during sessions
Document content7 daysImmutable once published
Election results30 daysUpdated only at elections
Economic indicators24 hoursDaily updates from World Bank

Rate Limiting

@Component
public class RateLimiter {

    private final Semaphore semaphore;
    private final ScheduledExecutorService scheduler;

    public RateLimiter(@Value("${api.rate.limit:10}") int maxRequestsPerSecond) {
        this.semaphore = new Semaphore(maxRequestsPerSecond);
        this.scheduler = Executors.newSingleThreadScheduledExecutor();
        this.scheduler.scheduleAtFixedRate(
            () -> semaphore.release(maxRequestsPerSecond - semaphore.availablePermits()),
            1, 1, TimeUnit.SECONDS
        );
    }

    public <T> T throttled(Supplier<T> apiCall) throws InterruptedException {
        semaphore.acquire();
        return apiCall.get();
    }
}

Error Handling

public class ApiIntegrationException extends RuntimeException {
    private final String operationName;
    private final int httpStatus;

    public ApiIntegrationException(String operationName, Throwable cause) {
        super("API integration failed: " + operationName, cause);
        this.operationName = operationName;
        this.httpStatus = extractStatus(cause);
    }
}

Security Considerations

  • Never log API keys or tokens — mask sensitive headers in logs
  • Validate all API responses — treat external data as untrusted input
  • Use HTTPS exclusively — reject insecure connections
  • Timeout connections — set connect (5s) and read (30s) timeouts
  • Sanitize data — escape or validate all data before database storage

ISMS Alignment

ControlRequirement
ISO 27001 A.8.24Use of cryptography for API transport
NIST CSF PR.DS-2Data-in-transit protection
CIS Control 12Network infrastructure management

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

37.02%
按下载量换算33

Claude

28.6%
按下载量换算26

Cursor

17.14%
按下载量换算15

Gemini CLI

9.12%
按下载量换算8

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills