Get the FREE Ultimate OpenClaw Setup Guide →

api-versioning-strategy

npx machina-cli add skill secondsky/claude-skills/api-versioning-strategy --openclaw
Files (1)
SKILL.md
2.1 KB

API Versioning Strategy

Choose and implement API versioning approaches with proper deprecation timelines.

Versioning Methods

MethodExampleProsCons
URL Path/api/v1/usersClear, cache-friendlyURL clutter
HeaderAPI-Version: 1Clean URLsHidden, harder to test
Query?version=1Easy to useNot RESTful

URL Path Versioning (Recommended)

const v1Router = require('./routes/v1');
const v2Router = require('./routes/v2');

app.use('/api/v1', v1Router);
app.use('/api/v2', v2Router);

Version Adapter Pattern

// Transform between versions
const v1ToV2 = (v1Response) => ({
  data: {
    type: 'user',
    id: v1Response.user_id,
    attributes: {
      name: v1Response.user_name,
      email: v1Response.email
    }
  }
});

Deprecation Headers

app.use('/api/v1', (req, res, next) => {
  res.setHeader('Deprecation', 'true');
  res.setHeader('Sunset', 'Sat, 01 Jun 2025 00:00:00 GMT');
  res.setHeader('Link', '</api/v2>; rel="successor-version"');
  next();
});

Safe vs Breaking Changes

Safe Changes (no version bump):

  • Adding optional fields
  • Adding new endpoints
  • Adding optional parameters

Breaking Changes (requires new version):

  • Removing fields
  • Changing field types
  • Restructuring responses
  • Removing endpoints

Deprecation Timeline

PhaseDurationActions
Deprecated3 monthsAdd headers, docs
Sunset Announced3 monthsEmail users
Read-Only1 monthDisable writes
Shutdown-Return 410 Gone

Best Practices

  • Support N-1 versions minimum
  • Provide 6+ months migration window
  • Include migration guides with code examples
  • Monitor version usage to inform deprecation

Source

git clone https://github.com/secondsky/claude-skills/blob/main/plugins/api-versioning-strategy/skills/api-versioning-strategy/SKILL.mdView on GitHub

Overview

Provides a structured approach to versioning your API using URL paths, headers, or query parameters. It emphasizes backward compatibility with deprecation timelines and migration paths to minimize client disruption. By supporting multiple versions concurrently, teams can plan breaking changes more safely.

How This Skill Works

Choose a versioning method (URL path, header, or query) and implement per-version routing or adapters. Use a Version Adapter Pattern to transform responses between versions. Deploy deprecation headers and a clear timeline to guide clients through migration and coexistence of versions.

When to Use It

  • You need to support legacy clients while introducing new features
  • You’re planning breaking changes and want a new version alongside the old one
  • You want clear, cache-friendly routes by version using URL paths
  • You want to emit deprecation signals (headers/links) and set sunset dates
  • You need to monitor version usage to determine when to deprecate old versions

Quick Start

  1. Step 1: Decide on a method (URL path is recommended) and set up versioned routers, e.g., app.use('/api/v1', v1Router); app.use('/api/v2', v2Router)
  2. Step 2: Implement a Version Adapter to transform older responses to the newer version if needed
  3. Step 3: Add Deprecation headers and define a migration timeline (Deprecated → Sunset Announced → Read-Only → Shutdown) with monitoring

Best Practices

  • Support N-1 versions minimum
  • Provide a 6+ months migration window
  • Include migration guides with code examples
  • Monitor version usage to inform deprecation
  • Define a clear deprecation timeline with phases (Deprecated, Sunset, Read-Only, Shutdown)

Example Use Cases

  • URL Path Versioning: mount v1 and v2 routers (e.g., app.use('/api/v1', v1Router); app.use('/api/v2', v2Router))
  • Version Adapter Pattern: implement v1ToV2(v1Response) to map fields to the new shape
  • Deprecation Headers: set Deprecation, Sunset, and Link: '</api/v2>; rel="successor-version"'
  • Safe vs Breaking Changes: classify additions as safe (optional fields/endpoints) vs breaking (removed fields/restructured responses)
  • Deprecation Timeline: follow phases such as Deprecated, Sunset Announced, Read-Only, Shutdown with appropriate actions

Frequently Asked Questions

Add this skill to your agents
Sponsor this space

Reach thousands of developers