Communitygithub.com

sickn33/api-patterns

API 设计原则与决策指南:涵盖 REST、GraphQL 与 tRPC 的选择、响应格式、版本控制及分页策略。

api-patterns 是什么?

该技能旨在帮助开发者及 AI 代理在 API 设计过程中做出明智的决策。它系统性地比较了 REST、GraphQL 和 tRPC 三种主流 API 架构的优缺点,适用于不同场景的选择。同时,它还提供了关于响应格式设计、API 版本控制策略以及分页实现模式的最佳实践。通过遵循这些原则,开发者可以构建出更一致、更易维护且性能更优的 API。该技能适用于任何需要设计或评估 API 架构的开发环境与 AI 代理平台。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/api-patterns

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

api-patterns 是做什么的?

API 设计原则与决策指南:涵盖 REST、GraphQL 与 tRPC 的选择、响应格式、版本控制及分页策略。

核心原则

  • 一致性:保持 API 行为与命名规则一致。
  • 可扩展性:设计时考虑未来的迭代与版本管理。
  • 面向客户端:根据客户端使用场景选择最优的交互模式。

协议对比

特性RESTGraphQLtRPC
数据获取多端点,按资源获取单一端点,客户端指定字段函数调用式,类型安全
类型安全依赖工具/文档通过 Schema 实现原生类型安全(全栈)
缓存HTTP 原生缓存支持需手动实现需自定义缓存策略
适用场景标准 CRUD 与资源型 API复杂数据聚合与灵活查询全栈 TypeScript 项目

响应格式

推荐使用统一的 JSON 响应结构:

{
  "success": true,
  "data": {},
  "error": null,
  "meta": {
    "timestamp": "2024-01-01T00:00:00Z",
    "requestId": "abc123"
  }
}

版本控制策略

  • URI 路径版本化(如 /v1/resource):简单直接,但可能导致重复代码。
  • 请求头版本化(如 Accept: application/vnd.api+json;version=1):更优雅,但实现复杂度稍高。
  • 查询参数版本化(如 ?version=1):不推荐,容易造成混淆。

分页模式

  • 基于游标的分页(Cursor-based):推荐用于实时数据与性能敏感场景。
  • 基于偏移的分页(Offset-based):适用于简单列表,但大偏移量下性能较差。
  • 基于时间戳的分页:适合按时间顺序排列的日志或事件数据。

示例:游标分页响应

{
  "data": [...],
  "pagination": {
    "cursor": "next_cursor_value",
    "hasMore": true,
    "total": 100
  }
}

相关资源

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

sickn33/3d-web-experience

Expert in building 3D experiences for the web - Three.js, React Three Fiber, Spline, WebGL, and interactive 3D scenes. Covers product configurators, 3D portfolios, immersive websites, and bringing depth to web experiences.

sickn33/agent-memory-mcp

A hybrid memory system that provides persistent, searchable knowledge management for AI agents (Architecture, Patterns, Decisions).

sickn33/agent-memory-systems

Memory is the cornerstone of intelligent agents. Without it, every interaction starts from zero. This skill covers the architecture of agent memory: short-term (context window), long-term (vector stores), and the cognitive architectures that organize them.

sickn33/ai-agents-architect

Expert in designing and building autonomous AI agents. Masters tool use, memory systems, planning strategies, and multi-agent orchestration.

sickn33/api-documentation-generator

Generate comprehensive, developer-friendly API documentation from code, including endpoints, parameters, examples, and best practices

sickn33/api-security-best-practices

Implement secure API design patterns including authentication, authorization, input validation, rate limiting, and protection against common API vulnerabilities

sickn33/app-store-optimization

Complete App Store Optimization (ASO) toolkit for researching, optimizing, and tracking mobile app performance on Apple App Store and Google Play Store

sickn33/architecture

Architectural decision-making framework. Requirements analysis, trade-off evaluation, ADR documentation. Use when making architecture decisions or analyzing system design.

sickn33/audio-transcriber

Transform audio recordings into professional Markdown documentation with intelligent summaries using LLM integration

sickn33/aws-serverless

Specialized skill for building production-ready serverless applications on AWS. Covers Lambda functions, API Gateway, DynamoDB, SQS/SNS event-driven patterns, SAM/CDK deployment, and cold start optimization.

sickn33/backend-architect

Expert backend architect specializing in scalable API design, microservices architecture, and distributed systems.

sickn33/backend-dev-guidelines

You are a senior backend engineer operating production-grade services under strict architectural and reliability constraints. Use when routes, controllers, services, repositories, express middleware, or prisma database access.

sickn33/bash-linux

Bash/Linux terminal patterns. Critical commands, piping, error handling, scripting. Use when working on macOS or Linux systems.

sickn33/bash-scripting

Bash scripting workflow for creating production-ready shell scripts with defensive patterns, error handling, and testing.

sickn33/brainstorming

Use before creative or constructive work (features, architecture, behavior). Transforms vague ideas into validated designs through disciplined reasoning and collaboration.

sickn33/browser-automation

Browser automation powers web testing, scraping, and AI agent interactions. The difference between a flaky script and a reliable system comes down to understanding selectors, waiting strategies, and anti-detection patterns.

sickn33/browser-extension-builder

Expert in building browser extensions that solve real problems - Chrome, Firefox, and cross-browser extensions. Covers extension architecture, manifest v3, content scripts, popup UIs, monetization strategies, and Chrome Web Store publishing.

sickn33/bullmq-specialist

BullMQ expert for Redis-backed job queues, background processing, and reliable async execution in Node.js/TypeScript applications.

sickn33/bun-development

Fast, modern JavaScript/TypeScript development with the Bun runtime, inspired by [oven-sh/bun](https://github.com/oven-sh/bun).

sickn33/cc-skill-security-review

This skill ensures all code follows security best practices and identifies potential vulnerabilities. Use when implementing authentication or authorization, handling user input or file uploads, or creating new API endpoints.

相关技能