api-changelog-versioning

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

API Changelog & Versioning

API变更日志与版本控制

Overview

概述

Create comprehensive API changelogs that document changes, deprecations, breaking changes, and provide migration guides for API consumers.
创建全面的API变更日志,记录变更、弃用项、破坏性变更,并为API使用者提供迁移指南。

When to Use

适用场景

  • API version changelogs
  • Breaking changes documentation
  • Migration guides between versions
  • Deprecation notices
  • API upgrade guides
  • Backward compatibility notes
  • Version comparison
  • API版本变更日志
  • 破坏性变更文档
  • 版本间迁移指南
  • 弃用通知
  • API升级指南
  • 向后兼容性说明
  • 版本对比

API Changelog Template

API变更日志模板

markdown
undefined
markdown
undefined

API Changelog

API Changelog

Version 3.0.0 - 2025-01-15

Version 3.0.0 - 2025-01-15

🚨 Breaking Changes

🚨 破坏性变更

Authentication Method Changed

认证方式变更

Previous (v2):
http
GET /api/users
Authorization: Token abc123
Current (v3):
http
GET /api/v3/users
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
Impact: All API consumers must switch from API tokens to JWT Bearer tokens
Migration Steps:
  1. Obtain JWT token from
    /api/v3/auth/login
    endpoint
  2. Replace
    Authorization: Token
    with
    Authorization: Bearer
  3. Update token refresh logic (JWT tokens expire after 1 hour)
Migration Deadline: June 1, 2025 (v2 auth will be deprecated)
Migration Guide: JWT Authentication Guide

旧版本(v2):
http
GET /api/users
Authorization: Token abc123
当前版本(v3):
http
GET /api/v3/users
Authorization: Bearer eyJhbGciOiJIUzI1NiIs...
影响: 所有API使用者必须从API令牌切换为JWT Bearer令牌
迁移步骤:
  1. /api/v3/auth/login
    端点获取JWT令牌
  2. Authorization: Token
    替换为
    Authorization: Bearer
  3. 更新令牌刷新逻辑(JWT令牌1小时后过期)
迁移截止日期: 2025年6月1日(v2认证将被弃用)
迁移指南: JWT认证指南

Response Format Changed

响应格式变更

Previous (v2):
json
{
  "id": "123",
  "name": "John Doe",
  "email": "john@example.com"
}
Current (v3):
json
{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  }
}
Impact: All API responses now follow JSON:API specification
Migration:
javascript
// Before (v2)
const user = await response.json();
console.log(user.name);

// After (v3)
const { data } = await response.json();
console.log(data.attributes.name);

// Or use our SDK which handles this automatically
import { ApiClient } from '@company/api-sdk';
const user = await client.users.get('123');
console.log(user.name); // SDK unwraps the response

旧版本(v2):
json
{
  "id": "123",
  "name": "John Doe",
  "email": "john@example.com"
}
当前版本(v3):
json
{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  }
}
影响: 所有API响应现在遵循JSON:API规范
迁移代码示例:
javascript
// 旧版本(v2)
const user = await response.json();
console.log(user.name);

// 当前版本(v3)
const { data } = await response.json();
console.log(data.attributes.name);

// 或使用我们的SDK自动处理
import { ApiClient } from '@company/api-sdk';
const user = await client.users.get('123');
console.log(user.name); // SDK会自动解析响应

Removed Endpoints

已移除的端点

Removed EndpointReplacementNotes
GET /api/users/list
GET /api/v3/users
Use pagination parameters
POST /api/users/create
POST /api/v3/users
RESTful convention
GET /api/search
GET /api/v3/search
Now supports advanced filters

已移除端点替代方案说明
GET /api/users/list
GET /api/v3/users
使用分页参数
POST /api/users/create
POST /api/v3/users
遵循RESTful规范
GET /api/search
GET /api/v3/search
现在支持高级筛选

✨ New Features

✨ 新功能

Webhook Support

Webhook支持

Subscribe to real-time events:
http
POST /api/v3/webhooks
Content-Type: application/json

{
  "url": "https://your-app.com/webhook",
  "events": ["user.created", "user.updated", "user.deleted"],
  "secret": "your-webhook-secret"
}
Webhook Payload:
json
{
  "event": "user.created",
  "timestamp": "2025-01-15T14:30:00Z",
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  }
}
Documentation: Webhook Guide

订阅实时事件:
http
POST /api/v3/webhooks
Content-Type: application/json

{
  "url": "https://your-app.com/webhook",
  "events": ["user.created", "user.updated", "user.deleted"],
  "secret": "your-webhook-secret"
}
Webhook负载:
json
{
  "event": "user.created",
  "timestamp": "2025-01-15T14:30:00Z",
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  }
}
文档: Webhook指南

Batch Operations

批量操作

Process multiple records in a single request:
http
POST /api/v3/users/batch
Content-Type: application/json

{
  "operations": [
    {
      "method": "POST",
      "path": "/users",
      "body": { "name": "User 1", "email": "user1@example.com" }
    },
    {
      "method": "PATCH",
      "path": "/users/123",
      "body": { "name": "Updated Name" }
    },
    {
      "method": "DELETE",
      "path": "/users/456"
    }
  ]
}
Response:
json
{
  "results": [
    { "status": 201, "data": { "id": "789", ... } },
    { "status": 200, "data": { "id": "123", ... } },
    { "status": 204 }
  ]
}
Limits: Maximum 100 operations per batch request

在单个请求中处理多条记录:
http
POST /api/v3/users/batch
Content-Type: application/json

{
  "operations": [
    {
      "method": "POST",
      "path": "/users",
      "body": { "name": "User 1", "email": "user1@example.com" }
    },
    {
      "method": "PATCH",
      "path": "/users/123",
      "body": { "name": "Updated Name" }
    },
    {
      "method": "DELETE",
      "path": "/users/456"
    }
  ]
}
响应:
json
{
  "results": [
    { "status": 201, "data": { "id": "789", ... } },
    { "status": 200, "data": { "id": "123", ... } },
    { "status": 204 }
  ]
}
限制: 每个批量请求最多支持100次操作

Field Filtering

字段筛选

Request only the fields you need:
http
GET /api/v3/users/123?fields=id,name,email
Before (full response):
json
{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com",
      "phone": "+1234567890",
      "address": { "street": "123 Main St", "city": "NYC" },
      "preferences": { /* ... */ },
      "metadata": { /* ... */ }
      // ... many more fields
    }
  }
}
After (filtered response):
json
{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  }
}
Benefits:
  • Reduced response size (up to 80% smaller)
  • Faster response times
  • Lower bandwidth usage

仅请求所需字段:
http
GET /api/v3/users/123?fields=id,name,email
旧版本(完整响应):
json
{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com",
      "phone": "+1234567890",
      "address": { "street": "123 Main St", "city": "NYC" },
      "preferences": { /* ... */ },
      "metadata": { /* ... */ }
      // ... 更多字段
    }
  }
}
当前版本(筛选后响应):
json
{
  "data": {
    "id": "123",
    "type": "user",
    "attributes": {
      "name": "John Doe",
      "email": "john@example.com"
    }
  }
}
优势:
  • 减小响应体积(最多可缩小80%)
  • 提升响应速度
  • 降低带宽消耗

🔧 Improvements

🔧 优化改进

Performance Enhancements

性能提升

  • 50% faster response times for list endpoints
  • Database query optimization reducing average query time from 150ms to 50ms
  • Caching layer added for frequently accessed resources
  • CDN integration for static assets
Benchmark Comparison:
Endpointv2 (avg)v3 (avg)Improvement
GET /users320ms140ms56% faster
GET /users/{id}180ms60ms67% faster
POST /users250ms120ms52% faster

  • 列表端点响应速度提升50%
  • 数据库查询优化,平均查询时间从150ms缩短至50ms
  • 为频繁访问的资源添加缓存层
  • 集成CDN处理静态资源
基准对比:
端点v2(平均)v3(平均)提升幅度
GET /users320ms140ms快56%
GET /users/{id}180ms60ms快67%
POST /users250ms120ms快52%

Better Error Messages

更友好的错误提示

Before (v2):
json
{
  "error": "Validation failed"
}
After (v3):
json
{
  "errors": [
    {
      "code": "VALIDATION_ERROR",
      "field": "email",
      "message": "Email format is invalid",
      "suggestion": "Use format: user@example.com"
    },
    {
      "code": "VALIDATION_ERROR",
      "field": "password",
      "message": "Password too weak",
      "suggestion": "Password must be at least 8 characters with uppercase, lowercase, and numbers"
    }
  ]
}

旧版本(v2):
json
{
  "error": "Validation failed"
}
当前版本(v3):
json
{
  "errors": [
    {
      "code": "VALIDATION_ERROR",
      "field": "email",
      "message": "Email format is invalid",
      "suggestion": "Use format: user@example.com"
    },
    {
      "code": "VALIDATION_ERROR",
      "field": "password",
      "message": "Password too weak",
      "suggestion": "Password must be at least 8 characters with uppercase, lowercase, and numbers"
    }
  ]
}

Enhanced Rate Limiting

增强的速率限制

New rate limit headers in every response:
http
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1642694400
X-RateLimit-Window: 3600
Retry-After: 3600
Rate Limits by Plan:
PlanRequests/HourBurstReset
Free10010/min1 hour
Pro1,00050/min1 hour
Enterprise10,000200/min1 hour

每个响应中都会包含新的速率限制头:
http
HTTP/1.1 200 OK
X-RateLimit-Limit: 1000
X-RateLimit-Remaining: 950
X-RateLimit-Reset: 1642694400
X-RateLimit-Window: 3600
Retry-After: 3600
按套餐划分的速率限制:
套餐每小时请求数突发请求数重置周期
免费版10010次/分钟1小时
专业版1,00050次/分钟1小时
企业版10,000200次/分钟1小时

🔒 Security

🔒 安全增强

  • TLS 1.3 Required: Dropped support for TLS 1.2
  • JWT Expiry: Tokens now expire after 1 hour (was 24 hours)
  • Rate Limiting: Stricter limits on authentication endpoints
  • CORS: Updated allowed origins (see security policy)
  • Input Validation: Enhanced validation on all endpoints

  • 要求使用TLS 1.3:不再支持TLS 1.2
  • JWT令牌有效期:从24小时缩短至1小时
  • 认证端点的速率限制更严格
  • CORS:更新了允许的源(请查看安全策略)
  • 输入验证:增强了所有端点的输入验证

🗑️ Deprecated

🗑️ 已弃用功能

Deprecation Schedule

弃用时间表

FeatureDeprecatedRemoval DateReplacement
API Token Authv3.0.02025-06-01JWT Bearer tokens
XML Response Formatv3.0.02025-04-01JSON only
/api/v1/*
endpoints
v3.0.02025-03-01
/api/v3/*
Query param
filter
v3.0.02025-05-01Use
filters[field]=value
Deprecation Warnings:
All deprecated features return a warning header:
http
HTTP/1.1 200 OK
Deprecation: true
Sunset: Sat, 01 Jun 2025 00:00:00 GMT
Link: <https://docs.example.com/migration/v2-to-v3>; rel="deprecation"

功能弃用版本移除日期替代方案
API令牌认证v3.0.02025-06-01JWT Bearer令牌
XML响应格式v3.0.02025-04-01仅支持JSON
/api/v1/*
端点
v3.0.02025-03-01
/api/v3/*
查询参数
filter
v3.0.02025-05-01使用
filters[field]=value
弃用警告:
所有已弃用功能都会返回警告头:
http
HTTP/1.1 200 OK
Deprecation: true
Sunset: Sat, 01 Jun 2025 00:00:00 GMT
Link: <https://docs.example.com/migration/v2-to-v3>; rel="deprecation"

📊 Version Support Policy

📊 版本支持政策

VersionStatusRelease DateEnd of Support
v3.xCurrent2025-01-15TBD
v2.xMaintenance2024-01-012025-07-01
v1.xEnd of Life2023-01-012024-12-31
Support Levels:
  • Current: Full support, new features
  • Maintenance: Bug fixes and security patches only
  • End of Life: No support, upgrade required

版本状态发布日期支持结束日期
v3.x当前版本2025-01-15待定
v2.x维护阶段2024-01-012025-07-01
v1.x停止支持2023-01-012024-12-31
支持级别:
  • 当前版本: 全面支持,会新增功能
  • 维护阶段: 仅修复Bug和安全漏洞
  • 停止支持: 不再提供任何支持,必须升级

Migration Guide: v2 → v3

迁移指南:v2 → v3

Step 1: Update Base URL

步骤1:更新基础URL

javascript
// Before
const API_BASE = 'https://api.example.com/api';

// After
const API_BASE = 'https://api.example.com/api/v3';
javascript
// 旧版本
const API_BASE = 'https://api.example.com/api';

// 当前版本
const API_BASE = 'https://api.example.com/api/v3';

Step 2: Migrate Authentication

步骤2:迁移认证方式

javascript
// Before (v2) - API Token
const response = await fetch(`${API_BASE}/users`, {
  headers: {
    'Authorization': `Token ${apiToken}`
  }
});

// After (v3) - JWT Bearer
const tokenResponse = await fetch(`${API_BASE}/auth/login`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email, password })
});
const { token } = await tokenResponse.json();

const response = await fetch(`${API_BASE}/users`, {
  headers: {
    'Authorization': `Bearer ${token}`
  }
});
javascript
// 旧版本(v2)- API令牌
const response = await fetch(`${API_BASE}/users`, {
  headers: {
    'Authorization': `Token ${apiToken}`
  }
});

// 当前版本(v3)- JWT Bearer
const tokenResponse = await fetch(`${API_BASE}/auth/login`, {
  method: 'POST',
  headers: { 'Content-Type': 'application/json' },
  body: JSON.stringify({ email, password })
});
const { token } = await tokenResponse.json();

const response = await fetch(`${API_BASE}/users`, {
  headers: {
    'Authorization': `Bearer ${token}`
  }
});

Step 3: Update Response Parsing

步骤3:更新响应解析逻辑

javascript
// Before (v2)
const user = await response.json();
console.log(user.name);

// After (v3) - Unwrap data object
const { data } = await response.json();
console.log(data.attributes.name);

// Or use SDK
import { ApiClient } from '@company/api-sdk';
const client = new ApiClient(token);
const user = await client.users.get('123');
console.log(user.name); // SDK handles unwrapping
javascript
// 旧版本(v2)
const user = await response.json();
console.log(user.name);

// 当前版本(v3)- 解析data对象
const { data } = await response.json();
console.log(data.attributes.name);

// 或使用SDK
import { ApiClient } from '@company/api-sdk';
const client = new ApiClient(token);
const user = await client.users.get('123');
console.log(user.name); // SDK会自动处理解析

Step 4: Update Error Handling

步骤4:更新错误处理

javascript
// Before (v2)
try {
  const response = await fetch(`${API_BASE}/users`);
  if (!response.ok) {
    const error = await response.json();
    console.error(error.error);
  }
} catch (error) {
  console.error(error);
}

// After (v3) - Handle multiple errors
try {
  const response = await fetch(`${API_BASE}/users`);
  if (!response.ok) {
    const { errors } = await response.json();
    errors.forEach(err => {
      console.error(`${err.field}: ${err.message}`);
      console.log(`Suggestion: ${err.suggestion}`);
    });
  }
} catch (error) {
  console.error(error);
}
javascript
// 旧版本(v2)
try {
  const response = await fetch(`${API_BASE}/users`);
  if (!response.ok) {
    const error = await response.json();
    console.error(error.error);
  }
} catch (error) {
  console.error(error);
}

// 当前版本(v3)- 处理多个错误
try {
  const response = await fetch(`${API_BASE}/users`);
  if (!response.ok) {
    const { errors } = await response.json();
    errors.forEach(err => {
      console.error(`${err.field}: ${err.message}`);
      console.log(`建议:${err.suggestion}`);
    });
  }
} catch (error) {
  console.error(error);
}

Step 5: Update Pagination

步骤5:更新分页逻辑

javascript
// Before (v2)
const response = await fetch(`${API_BASE}/users?page=1&per_page=20`);

// After (v3)
const response = await fetch(`${API_BASE}/users?page[number]=1&page[size]=20`);

// Response structure
{
  "data": [...],
  "meta": {
    "page": {
      "current": 1,
      "size": 20,
      "total": 150,
      "totalPages": 8
    }
  },
  "links": {
    "first": "/api/v3/users?page[number]=1",
    "last": "/api/v3/users?page[number]=8",
    "next": "/api/v3/users?page[number]=2",
    "prev": null
  }
}
javascript
// 旧版本(v2)
const response = await fetch(`${API_BASE}/users?page=1&per_page=20`);

// 当前版本(v3)
const response = await fetch(`${API_BASE}/users?page[number]=1&page[size]=20`);

// 响应结构
{
  "data": [...],
  "meta": {
    "page": {
      "current": 1,
      "size": 20,
      "total": 150,
      "totalPages": 8
    }
  },
  "links": {
    "first": "/api/v3/users?page[number]=1",
    "last": "/api/v3/users?page[number]=8",
    "next": "/api/v3/users?page[number]=2",
    "prev": null
  }
}

Step 6: Testing

步骤6:测试

javascript
// Run tests against v3 API
npm run test:api -- --api-version=v3

// Test migration gradually
const USE_V3 = process.env.USE_API_V3 === 'true';
const API_BASE = USE_V3
  ? 'https://api.example.com/api/v3'
  : 'https://api.example.com/api/v2';

javascript
// 针对v3 API运行测试
npm run test:api -- --api-version=v3

// 逐步测试迁移
const USE_V3 = process.env.USE_API_V3 === 'true';
const API_BASE = USE_V3
  ? 'https://api.example.com/api/v3'
  : 'https://api.example.com/api/v2';

Version Comparison

版本对比

Feature Matrix

功能矩阵

Featurev1v2v3
REST API
GraphQL
Webhooks
Batch Operations
Field Filtering
JSON:API Format
JWT Auth
API Token Auth⚠️ Deprecated
XML Responses⚠️ Deprecated
Legend: ✅ Supported | ❌ Not Available | ⚠️ Deprecated

功能v1v2v3
REST API✅ 支持✅ 支持✅ 支持
GraphQL❌ 不支持❌ 不支持✅ 支持
Webhooks❌ 不支持❌ 不支持✅ 支持
批量操作❌ 不支持❌ 不支持✅ 支持
字段筛选❌ 不支持✅ 支持✅ 支持
JSON:API格式❌ 不支持❌ 不支持✅ 支持
JWT认证❌ 不支持✅ 支持✅ 支持
API令牌认证✅ 支持✅ 支持⚠️ 已弃用
XML响应✅ 支持⚠️ 已弃用❌ 不支持
图例:✅ 支持 | ❌ 不支持 | ⚠️ 已弃用

SDK Updates

SDK更新

Update to the latest SDK version:
bash
undefined
升级到最新版本的SDK:
bash
undefined

JavaScript/TypeScript

JavaScript/TypeScript

npm install @company/api-sdk@^3.0.0
npm install @company/api-sdk@^3.0.0

Python

Python

pip install company-api-sdk>=3.0.0
pip install company-api-sdk>=3.0.0

Ruby

Ruby

gem install company-api-sdk -v '~> 3.0'
gem install company-api-sdk -v '~> 3.0'

Go

Go

go get github.com/company/api-sdk/v3

**SDK Changelog:** [SDK Releases](https://github.com/company/api-sdk/releases)

---
go get github.com/company/api-sdk/v3

**SDK变更日志:** [SDK版本发布记录](https://github.com/company/api-sdk/releases)

---

Support & Resources

支持与资源

undefined
undefined

Best Practices

最佳实践

✅ DO

✅ 建议做法

  • Clearly mark breaking changes
  • Provide migration guides with code examples
  • Include before/after comparisons
  • Document deprecation timelines
  • Show impact on existing implementations
  • Provide SDKs for major versions
  • Use semantic versioning
  • Give advance notice (3-6 months)
  • Maintain backward compatibility when possible
  • Document version support policy
  • 清晰标记破坏性变更
  • 提供包含代码示例的迁移指南
  • 包含新旧版本对比
  • 记录弃用时间线
  • 说明对现有实现的影响
  • 为主要版本提供SDK
  • 使用语义化版本控制
  • 提前通知(3-6个月)
  • 尽可能保持向后兼容性
  • 记录版本支持政策

❌ DON'T

❌ 避免做法

  • Make breaking changes without notice
  • Remove endpoints without deprecation period
  • Skip migration examples
  • Forget to version your API
  • Change behavior without documentation
  • Rush deprecations
  • 未提前通知就进行破坏性变更
  • 没有弃用周期就移除端点
  • 省略迁移示例
  • 不对API进行版本控制
  • 变更行为但不更新文档
  • 仓促推进弃用流程

Resources

参考资源