api-best-practices
БесплатноБез исполняемых скриптовНе проверенREST API design patterns, OpenAPI specifications, versioning strategies, authentication, error handling, and security best practices. Use when designing APIs…
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
API Best Practices
This skill provides comprehensive guidance for designing, implementing, and documenting RESTful APIs following industry best practices.
RESTful Design Principles
Resource-Oriented Design
APIs should be designed around resources (nouns), not actions (verbs):
Good:
GET /api/v1/users
POST /api/v1/users
GET /api/v1/users/{id}
PUT /api/v1/users/{id}
DELETE /api/v1/users/{id}
Bad:
GET /api/v1/getUsers
POST /api/v1/createUser
POST /api/v1/updateUser
POST /api/v1/deleteUser
HTTP Methods and Their Meanings
- GET: Retrieve a resource (safe, idempotent, cacheable)
- POST: Create a new resource (not idempotent)
- PUT: Replace entire resource (idempotent)
- PATCH: Partial update (not necessarily idempotent)
- DELETE: Remove a resource (idempotent)
HTTP Status Codes
Success (2xx):
200 OK: Successful GET, PUT, PATCH, DELETE201 Created: Successful POST with resource creation202 Accepted: Request accepted for async processing204 No Content: Successful DELETE or update with no response body
Client Errors (4xx):
400 Bad Request: Malformed request, validation error401 Unauthorized: Authentication required403 Forbidden: Authenticated but not authorized404 Not Found: Resource doesn't exist409 Conflict: Resource conflict (duplicate, version mismatch)422 Unprocessable Entity: Valid syntax but semantic errors429 Too Many Requests: Rate limit exceeded
Server Errors (5xx):
500 Internal Server Error: Unexpected server error502 Bad Gateway: Upstream service failure503 Service Unavailable: Temporary overload or maintenance504 Gateway Timeout: Upstream timeout
API Versioning
URL Versioning (Recommended)
GET /api/v1/users
GET /api/v2/users
Pros: Clear, easy to route, visible in logs Cons: Duplicate code across versions
Header Versioning
GET /api/users
Accept: application/vnd.myapi.v1+json
Pros: Clean URLs Cons: Harder to test, less visible
Version Management Rules
- Never break backwards compatibility in same version
- Deprecate old versions with advance notice (6-12 months)
- Document migration guides between versions
- Support at least 2 major versions simultaneously
Request/Response Patterns
Standard Request Format
JSON Request Body:
{
"email": "[email protected]",
"name": "John Doe",
"preferences": {
"newsletter": true,
"notifications": false
}
}
Query Parameters (for filtering, pagination, sorting):
GET /api/v1/users?role=admin&status=active&page=2&limit=20&sort=-created_at
Standard Response Format
Success Response:
{
"data": {
"id": "user_123",
"email": "[email protected]",
"name": "John Doe",
"createdAt": "2025-10-16T10:30:00Z"
}
}
Error Response:
{
"error": {
"code": "INVALID_EMAIL",
"message": "Email address is invalid",
"field": "email",
"details": "Email must contain @ symbol"
}
}
Collection Response with Pagination:
{
"data": [
{ "id": 1, "name": "User 1" },
{ "id": 2, "name": "User 2" }
],
"pagination": {
"page": 2,
"limit": 20,
"total": 156,
"totalPages": 8,
"hasNext": true,
"hasPrev": true
},
"links": {
"self": "/api/v1/users?page=2",
"next": "/api/v1/users?page=3",
"prev": "/api/v1/users?page=1",
"first": "/api/v1/users?page=1",
"last": "/api/v1/users?page=8"
}
}
Authentication Patterns
JWT (JSON Web Tokens)
Login Flow:
POST /api/v1/auth/login
{
"email": "[email protected]",
"password": "SecurePassword123"
}
Response (200):
{
"accessToken": "eyJhbGc...",
"refreshToken": "eyJhbGc...",
"expiresIn": 900
}
Using Access Token:
GET /api/v1/users/me
Authorization: Bearer eyJhbGc...
Token Refresh:
POST /api/v1/auth/refresh
{
"refreshToken": "eyJhbGc..."
}
Response (200):
{
"accessToken": "eyJhbGc...",
"expiresIn": 900
}
API Keys
Header-based (recommended):
GET /api/v1/data
X-API-Key: sk_live_abc123xyz
Query parameter (less secure, use only for public data):
GET /api/v1/public-data?api_key=sk_live_abc123xyz
OAuth 2.0 Flows
Authorization Code Flow (for web apps):
- Redirect to
/oauth/authorize - User grants permission
- Receive authorization code
- Exchange code for access token at
/oauth/token - Use access token for API requests
Client Credentials Flow (for server-to-server):
POST /oauth/token
Content-Type: application/x-www-form-urlencoded
grant_type=client_credentials&client_id=abc&client_secret=xyz
Error Handling
Validation Errors
{
"error": {
"code": "VALIDATION_ERROR",
"message": "Request validation failed",
"errors": [
{
"field": "email",
"messag
Установить api-best-practices в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл api-best-practices?
REST API design patterns, OpenAPI specifications, versioning strategies, authentication, error handling, and security best practices. Use when designing APIs, creating endpoints, documenting APIs, or implementing backend services that expose HTTP APIs.
Как установить скилл api-best-practices?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл api-best-practices запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic