Token导航 LogoToken导航TokenDH.com
开发需要联网github未标认证来源可访问许可证需确认审计通过

engineering-rest-api-designengineering rest API 设计

Agent Skill

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

总安装

218

周安装

9

GitHub Stars

4

下载量

71
CodexClaudeCursorGemini CLI

安装说明

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

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

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

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

命令行安装

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

skills.shnpx skills
npx skills add https://github.com/jimnguyendev/jimmy-skills --skill engineering-rest-api-design

简介

用于 RESTful API 设计与文档编写,遵循消费者优先的设计原则。

  • 提供命名规范、错误封装、分页机制与异步模式等最佳实践指引。
  • 可辅助生成 OpenAPI 草稿并审计现有接口合规性。
  • 生成文档时应基于已有 schema 或接口样例,避免虚构字段定义。
  • engineering-rest-api-design 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Persona: You are a senior API architect. Every endpoint you design is a contract — once published, it becomes someone else's dependency. Design for the consumer first, optimize for the maintainer second.

Modes:

  • Design mode — designing new endpoints: apply conventions top-down, validate against checklist in references/checklist.md.
  • Review mode — reviewing existing API contracts: audit naming, pagination, error envelope, idempotency, and async patterns against this skill's rules. Flag violations with severity (breaking / inconsistent / style).
  • Document mode — writing API documentation: follow the spec template in references/api-document-template.md.

REST API Design

Mindset

  1. Design first — think at the high level, cover edge cases on paper, reduce implementation cost.
  2. Scalable — endpoints should handle growth in consumers, data volume, and team size.
  3. Consistent — one convention across all services; deviation requires justification.
  4. Inspect every aspect — URL, method, headers, body, pagination, errors, async behavior.
  5. No one-size-fits-all — document trade-offs explicitly when deviating from conventions.

HTTP Methods

MethodOperationSafeIdempotent
GETReadYesYes
POSTCreate / Batch readNoNo
PUTUpdate (full or partial)NoYes
DELETERemove / disableNoYes

Safety means the method does not alter server state. Idempotency means sending the same request multiple times produces the same result.

PUT over PATCH — use PUT for all updates. Clients always send the full set of mutable fields. This eliminates ambiguity about which fields are being changed vs intentionally omitted, and keeps the operation unconditionally idempotent. Do not use PATCH.

POST for batch reads — when fetching multiple resources by a list of IDs, use POST with a JSON body instead of GET with query parameters. GET query strings have length limits and become unwieldy with many IDs. Pattern: POST /resources/batch with body {"ids": ["id1", "id2"]}.

Create returns 200 — POST create endpoints return 200 with the created resource in the response body. Do not use 201 Created. This simplifies client handling — consumers check the same status code for all successful operations.

For non-idempotent POST requests, use a unique request ID or Idempotency-Key header so the server can detect and deduplicate retries.

URL Conventions

Rules

  1. Nouns, not verbs — the resource is the noun, the method is the verb.
  2. Plural nouns/users, not /user.
  3. Nesting for relationships/articles/{article_id}/comments.
  4. Versioning in path/api/v1/....
  5. Slug-case for URLs/order-service/v1/orders.
  6. snake_case for request and response body{"debit_account": "acc01"}.

Singular vs Plural

Use plural by default. Use singular only when the resource is inherently unique within its parent:

GET /api/users/{id}/profile          # one profile per user → singular
GET /api/users/{id}/profile/addresses/{address_id}  # multiple addresses → plural
GET /api/forms/login                 # one login form among many forms → singular

Custom Actions

When CRUD methods are insufficient (restore, publish, archive), use one of:

Colon method (Google API convention) — clearly separates action from sub-resource:

POST /files/{id}:restore
POST /v1/{resource}:setIamPolicy

Slash method — simpler but risks confusion with sub-resources:

POST /files/{id}/restore

Prefer the colon method when clarity matters. The slash method is acceptable if the team prefers familiar URL conventions and there is no ambiguity with actual sub-resources.

Examples

POST   /order-service/v1/orders              # create
GET    /order-service/v1/orders/145           # get by ID
POST   /order-service/v1/orders/batch         # batch get by IDs
PUT    /order-service/v1/orders/145           # update
DELETE /order-service/v1/orders/145           # delete

Pagination

Two common approaches — choose based on use case, stay consistent within a service.

Page + Size

GET /users?page=0&size=10
  • Best for: management portals, admin dashboards.
  • Must document: whether page starts at 0 or 1.

Offset + Limit

GET /users?offset=0&limit=10
  • Best for: infinite scroll, newsfeeds, log streams.

Known Problems

  1. Performance on large datasetsOFFSET N scans and discards N rows.
  2. Resource skipping — deleting records between paginated requests shifts items across page boundaries.

Solutions

Cursor-based pagination — use the last seen ID as a cursor:

SELECT * FROM users WHERE id > :last_id ORDER BY id LIMIT 10;

Deferred join — fetch IDs first, then join:

SELECT * FROM (
  SELECT id FROM users ORDER BY id LIMIT 100, 10
) a JOIN users b ON a.id = b.id;

See references/pagination-patterns.md for full comparison of all pagination strategies with decision guide.

Filtering

Use query parameters to narrow results. Multiple filters combine with AND logic:

GET /products?price=20&brand=Nike
GET /orders?status=pending&created_after=2024-01-01

For complex filtering (range, OR, nested), document the query language explicitly. Never pass filter values directly into SQL — always parameterize.

Sorting

Three common conventions — pick one per API, stay consistent:

# Format A: colon separates field:direction, comma separates fields
GET /products?sort=price:asc,name:desc

# Format B: prefix +/- for direction
GET /products?sort=+price,-name

# Format C: comma separates field,direction pairs, semicolon separates fields
GET /articles?sort=publish_date,asc;title,desc

Default sort direction should be documented (typically descending for dates, ascending for names). Always whitelist sortable fields — never pass user input directly to ORDER BY.

Relationship Endpoints

One-to-Many

GET /articles/{article_id}/comments

Many-to-Many

GET  /classes/{class_id}/students
POST /classes/{class_id}/students/{student_id}
POST /classes/{class_id}/students          # bulk add via body

Note: PUT /classes/{class_id}/students/{student_id} is acceptable because the operation is idempotent (adding an already-added student has no additional effect).

Async API Pattern

For long-running operations (file export, report generation, bulk processing) where synchronous response risks timeout, memory exhaustion, or client blocking.

Job-based Flow

# 1. Initiate the job
POST /products/jobs/export?name=pen
→ 202 Accepted
{
  "meta": { "code": "202000", "type": "ACCEPTED", "message": "Job created", "service_id": "product-service" },
  "data": { "job_id": "001", "status": "PROCESSING" }
}

# 2. Poll job status
GET /jobs/001
→ 200
{
  "meta": { "code": "200000", "type": "SUCCESS", "message": "Success", "service_id": "product-service" },
  "data": { "job_id": "001", "status": "COMPLETED" }
}

# 3. Retrieve result
GET /jobs/001/result
→ 200 (file download or data in standard envelope)

Polling vs Webhook

ApproachProsConsUse case
PollingSimple to implementWastes resourcesSmall load, import/export
Webhook / CallbackResource-efficientComplex on both sidesLarge load, payment

Versioning

See references/versioning.md for full comparison. Summary:

StrategyExampleProsCons
URL path/v1/ordersVisible, simpleNew URL per version
Channel/v1/beta/ordersStaged rolloutMore paths to manage
HeaderApi-Version: 2URL stays cleanHidden, easy to miss
Query param/orders?version=2FlexibleEasy to forget

Default recommendation: URL path versioning (/v1/). Consider channels (v1alpha, v1beta, v1) for APIs with staged release processes.

If the API is internal and all clients can be updated together, versioning may be unnecessary.

Rate Limiting

Control request volume to protect backend resources and ensure fair usage.

Response for exceeded limits: return 429 Too Many Requests.

Inform clients via headers:

X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 500
X-RateLimit-Reset: 1588377600
Retry-After: 120

Idempotency

Problem: A request may be sent twice due to network issues or replay attacks. Critical for payment, order, and financial operations.

Solution: Client generates an Idempotency-Key header (or a unique request/transaction ID). Server enforces uniqueness via a unique constraint in the database. On duplicate, server returns the original response — not an error.

POST /payment-service/v1/payments
Headers:
  Content-Type: application/json
  Idempotency-Key: oc8tKg1P2FV44hpj

Response Envelope

Standard envelope structure for all API responses:

{
  "meta": {
    "code": "200000",
    "type": "SUCCESS",
    "message": "Success",
    "service_id": "payment-service",
    "extra_meta": {}
  },
  "data": { ... }
}

Error responses use the same envelope with "data": null:

{
  "meta": {
    "code": "400001",
    "type": "INSUFFICIENT_DEBIT_AMOUNT",
    "message": "Debit account has an insufficient amount of balance",
    "service_id": "payment-service",
    "extra_meta": {}
  },
  "data": null
}

API Documentation

Every endpoint must be documented with: spec (method, URL, headers, body), request body field table, response body field table, error table, and cURL sample. See references/api-document-template.md for the full template.

Cross-References

  • For backend implementation of these patterns, start with jimmy-skills@backend-core.
  • For Go-specific HTTP handler details, use jimmy-skills@backend-go-code-style.
  • For MyVocab project-specific response envelope and handler patterns, use jimmy-skills@myvocap-backend.
  • For error handling conventions in Go, use jimmy-skills@backend-go-error-handling.
  • For database query patterns (pagination SQL), use jimmy-skills@backend-go-database.

External Sources

This skill synthesizes conventions from established API design references. Official documentation remains authoritative:

适合场景

01

用户想查找某类 Agent Skill 时

02

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

03

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

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

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

能力 4

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

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

平台分布

Codex

36.39%
按下载量换算26

Claude

27.14%
按下载量换算19

Cursor

17.75%
按下载量换算13

Gemini CLI

8.96%
按下载量换算6

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

通过

权限和风险

需要联网

该 Skill 可能需要联网访问来源站点、仓库或外部 API;具体网络访问范围需要结合源码和 README 复核。

安装前确认

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

来源信息

继续浏览同类 Skills