跳到正文
Skillpedia
API 与服务器(后端)48k · #3776

api-patterns

它能做什么

这份指南可以帮助你为不同程序之间的通信做出重要决策,也就是设计它们相互“对话”所用的“语言”(API)。它会教你选择最合适的风格(比如 REST 或 GraphQL),并规定数据如何发送和接收。

适用场景

  • ✓在决定使用 REST、GraphQL 还是其他通信方式时。
  • ✓在规定程序如何返回数据时。
  • ✓在规划系统如何应对大量访问或更新时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-patterns/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/api-patterns/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“我应该怎样设计 API 的响应,才能既方便用户使用又足够安全?”

每周 5 个新技能,1 分钟读完。

工作原理

这份指南提供了一张“地图”,帮你找到关于每种 API 类型及其规则的正确信息。它会促使你在做决定之前,先考虑 API 用户的需求。

技术内容(原始 SKILL.md)

作者在 GitHub 上的英文原文。

API Patterns

API design decisions tied to the consumers and deployment constraints. Learn to THINK, not copy fixed patterns.

🎯 Selective Reading Rule

Read ONLY files relevant to the request! Check the content map, find what you need.


📑 Content Map

File Description When to Read
api-style.md REST vs GraphQL vs tRPC decision tree Choosing API type
rest.md Resource naming, HTTP methods, status codes Designing REST API
response.md Envelope pattern, error format, pagination Response structure
graphql.md Schema design, when to use, security Considering GraphQL
trpc.md TypeScript monorepo, type safety TS fullstack projects
versioning.md URI/Header/Query versioning API evolution planning
auth.md JWT, OAuth, Passkey, API Keys Auth pattern selection
rate-limiting.md Token bucket, sliding window API protection
documentation.md OpenAPI/Swagger best practices Documentation
security-testing.md OWASP API Top 10, auth/authz testing Security audits

🔗 Related Skills

Need Skill
API implementation @[skills/backend-architect]
Data structure @[skills/database-design]
Security details @[skills/api-security-best-practices]

✅ Decision Checklist

Before designing an API:

  • Asked user about API consumers?
  • Chosen API style for THIS context? (REST/GraphQL/tRPC)
  • Defined consistent response format?
  • Planned versioning strategy?
  • Considered authentication needs?
  • Planned rate limiting?
  • Documentation approach defined?

❌ Anti-Patterns

DON'T:

  • Default to REST for everything
  • Use verbs in REST endpoints (/getUsers)
  • Return inconsistent response formats
  • Expose internal errors to clients
  • Skip rate limiting

DO:

  • Choose API style based on context
  • Ask about client requirements
  • Document thoroughly
  • Use appropriate status codes

Script

Script Purpose Command
scripts/api_validator.py Local heuristic source scan (not schema validation) python3 skills/api-patterns/scripts/api_validator.py <project_path>

When to Use

Use when defining a new endpoint contract, selecting REST/GraphQL/tRPC for known consumers, or changing pagination, errors, authentication or compatibility behavior. For a bug inside an existing contract, preserve that contract unless the task authorizes a change.

Inputs and procedure

Record consumers and deployed versions, expected payload size, access rules, compatibility obligations and one concrete operation. Read the relevant files in the map, compare the realistic choices, then specify request/response examples and rejection cases. Types shared at build time do not ensure that independently deployed clients remain compatible.

Worked example

Input: a public order list changes while clients page through it. Choose a bounded page size and cursor over a stable (created_at, id) order. Define the next-cursor format, authorization filter and behavior for a removed record or invalid cursor. Test two equal timestamps and an insertion between pages. Expected: no duplicate IDs within the promised snapshot semantics; document whether newly inserted rows can appear.

Limitations

  • The Python helper scans at most 15 matching files using regular expressions and shallow JSON/YAML checks. Its output is a triage hint, not OpenAPI validation, an authorization audit or deployment approval.
  • GraphQL query shape, tRPC inference and HTTP method names do not enforce resource authorization or backwards compatibility.
  • Rate limiting cannot alone prevent all resource exhaustion; size, concurrency, time and provider-cost bounds depend on the operation.
  • Perform security checks only against authorized local/test targets with isolated accounts and a defined scope.
常见问题

什么是 API?

API 就像餐厅的菜单。它告诉你有哪些菜(信息或操作)可以点,以及怎样点,而你不需要了解厨房(程序)是怎么运作的。

REST、GraphQL 和 tRPC 该怎么选?

它们各有优势。REST 常见且简单,GraphQL 在获取特定数据时很灵活,tRPC 则适合使用 TypeScript、且需要类型安全的项目。

为什么 API 版本管理很重要?

版本管理可以确保以后对 API“语言”的修改不会破坏仍在使用它的程序。这就像发布应用的新版本时,不会弄坏旧功能一样。

详情

作者的原始描述

API design principles and decision-making. REST vs GraphQL vs tRPC selection, response formats, versioning, pagination.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#3776
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能