← 返回
未分类 中文

Rest Best Practices

Deep REST workflow—resource modeling, HTTP methods and safety, status codes, errors, pagination, caching, versioning, and idempotency. Use when designing HTT...
深度REST工作流——资源建模、HTTP方法与安全性、状态码、错误处理、分页、缓存、版本控制和幂等性。用于设计HTTP...
mike47512 mike47512 来源
未分类 clawhub v1.0.0 1 版本 100000 Key: 无需
★ 0
Stars
📥 428
下载
💾 0
安装
1
版本
#latest

概述

REST Best Practices (Deep Workflow)

REST is HTTP semantics used consistently: resources as nouns, methods with meaning, predictable errors, and cacheable reads where safe.

When to Offer This Workflow

Trigger conditions:

  • Designing public or partner HTTP APIs
  • Inconsistent verbs (GET with side effects); wrong status codes
  • CDN/caching surprises; client retry storms on POST

Initial offer:

Use six stages: (1) resource model, (2) methods & safety, (3) status & errors, (4) pagination & filtering, (5) caching & conditional requests, (6) versioning & evolution). Confirm JSON conventions and authentication model.


Stage 1: Resource Model

Goal: Clear collection vs item resources; relationships via sub-paths or hypermedia links (HATEOAS optional).

Exit condition: Table or diagram of resources, identifiers, and canonical URLs.


Stage 2: Methods & Safety

Goal: GET/HEAD safe and idempotent; POST for creation or non-idempotent actions; PUT replaces; PATCH partial; DELETE removes.

Anti-patterns

  • Non-idempotent GET; overloaded POST for everything without documented patterns

Stage 3: Status & Errors

Goal: Correct 4xx vs 5xx; consistent error body (e.g., RFC 7807 Problem Details) with stable type codes and optional instance for support.


Stage 4: Pagination & Filtering

Goal: Cursor pagination for large lists; document sort/filter query params; cap page sizes.


Stage 5: Caching & Conditional Requests

Goal: ETag/Last-Modified for cacheable GET; Cache-Control directives; validate with intermediaries (CDN) when used.


Stage 6: Versioning & Evolution

Goal: URL prefix or header versioning; deprecation policy; Idempotency-Key on POST when clients retry.


Final Review Checklist

  • [ ] Resource model clear and consistent
  • [ ] HTTP methods match semantics; GET is safe
  • [ ] Status codes and errors consistent
  • [ ] Pagination and filtering documented
  • [ ] Caching headers where appropriate
  • [ ] Versioning and idempotency strategy

Tips for Effective Guidance

  • Not everything is CRUD—model commands as sub-resources or task resources explicitly.
  • Pair with openapi-spec for contract-first workflows.

Handling Deviations

  • Internal APIs still benefit from the same discipline—future consumers are often external.

版本历史

共 1 个版本

  • v1.0.0 当前
    2026-03-31 06:16 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

design-media

Visual

mike47512
提供平面设计、UI交互、PPT美化及品牌调性升级指引。
★ 0 📥 2,357
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 686 📥 330,952
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 81 📥 182,998