Skip to content
Back to skills

Rest Api Design

ASecurity

>

  • 8 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added September 12, 2026
documentationexpressapidocumentation

Works with

  • api

Security analysis

A100/100

Pro scans all 10 files and shows the line behind each finding

Scanned September 12, 2026

npx -y skills add lza6/Claude-code-cli-config --skill rest-api-design --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Rest Api Design?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Rest Api Design
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lza6-rest-api-design/badge)](https://www.skillsdirectory.com/skills/lza6-rest-api-design)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: rest-api-design
description: ">"
  遵循资源建模、HTTP 方法、状态码、版本控制和文档的最佳实践设计 RESTful API。
  在创建新 API、设计端点或改进现有 API 架构时使用。
---

# REST API 设计

## 目录

- [概述](#概述)
- [何时使用](#何时使用)
- [快速启动](#快速启动)
- [参考指南](#参考指南)
- [最佳实践](#最佳实践)

## 概述

设计直观、一致的 REST API,并遵循面向资源的架构的行业最佳实践。

## 何时使用

- 设计新的 RESTful API
- 创建端点结构
- 定义请求/响应格式
- 实施 API 版本控制
- 记录 API 规范
- 重构现有 API

## 快速入门

最小工作示例:

```
✅ 正确的资源命名(名词,复数)
GET    /api/users
GET    /api/users/123
GET    /api/users/123/orders
POST   /api/products
DELETE /api/products/456

❌ 错误的资源命名(动词,不一致)
GET    /api/getUsers
POST   /api/createProduct
GET    /api/user/123  (单复数不一致)
```

## 参考指南

详细实现在 `references/` 目录中:

| 指南 | 内容 |
|---|---|
| [资源命名](references/resource-naming.md) | 资源命名、HTTP 方法和操作 |
| [请求示例](references/request-examples.md) | 请求示例 |
| [查询参数](references/query-parameters.md) | 查询参数 |
| [响应格式](references/response-formats.md) | 响应格式 |
| [HTTP 状态码](references/http-status-codes.md) | HTTP 状态码、API 版本控制、身份验证和安全性、速率限制标头 |
| [OpenAPI 文档](references/openapi-documentation.md) | OpenAPI 文档 |
| [完整示例:Express.js](references/complete-example-expressjs.md) | Express.js 完整示例 |

## 最佳实践

### ✅ 应该做

- 使用名词来表示资源,而不是动词
- 集合使用复数名称
- 与命名约定保持一致
- 返回适当的 HTTP 状态码
- 包括集合的分页
- 提供过滤和排序选项
- 版本化你的 API
- 使用 OpenAPI 进行详细文档
- 使用 HTTPS
- 实施速率限制
- 提供清晰的错误消息
- 使用 ISO 8601 日期格式

### ❌ 不应该做

- 在端点名称中使用动词
- 错误地返回 200
- 不必要地暴露内部 ID
- 过度嵌套资源(最多 2 层)
- 使用不一致的命名
- 忘记身份验证
- 返回敏感数据
- 在不版本化的情况下破坏向后兼容性

Files in this skill

  • SKILL.md2.3 KB
  • references/complete-example-expressjs.md2.5 KB
  • references/http-status-codes.md1.3 KB
  • references/openapi-documentation.md1.8 KB
  • references/query-parameters.md397 B
  • references/request-examples.md733 B
  • references/resource-naming.md944 B
  • references/response-formats.md1.1 KB
  • scripts/validate-api.sh440 B
  • templates/api-scaffold.yaml467 B

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…