From rails-agent-skills
Implements Rails REST API versioning via URL paths or Accept headers, deprecation policies, and backward compatibility. Use for adding v1/v2, API evolution, sunset policies, or compatibility checks.
npx claudepluginhub igmarin/rails-agent-skills --plugin rails-agent-skillsThis skill uses the workspace's default tool permissions.
Implement versioning strategies for Rails APIs.
Implements API versioning via URL paths, headers, or query params with backward compatibility, deprecation headers, migration paths, and OpenAPI-based breaking change detection.
Implements API versioning using URL paths, headers, or query parameters with deprecation timelines, backward compatibility, and migration strategies. Use for managing multiple versions or planning breaking changes.
Guides API versioning strategies including URL path, header, query parameter, and content negotiation. Helps manage breaking changes, deprecations, and multiple versions.
Share bugs, ideas, or general feedback.
Implement versioning strategies for Rails APIs.
Files: SKILL.md · EXAMPLES.md · references/workflow.md · references/strategies.md
ALWAYS maintain backward compatibility for at least one major version
NEVER remove endpoints without deprecation period
ALWAYS version in URL path (/api/v1/) or Accept header, never in body
| Concern | File |
|---|---|
| Route namespaces | config/routes.rb |
| Header versioning | app/controllers/concerns/api_versioning.rb |
| Deprecation headers | app/controllers/concerns/deprecatable.rb |
| Compatibility specs | spec/requests/api/backward_compatibility_spec.rb |
/api/v1/) for public APIs; Accept header for internal/private APIs.namespace :v2 block in config/routes.rb.Deprecatable in old-version controllers to emit sunset headers.rspec spec/requests/api/backward_compatibility_spec.rb to confirm no regressions.See references/workflow.md for the complete annotated workflow.
namespace :v1 do
resources :users
end
namespace :v2 do
resources :users
end
Override only actions that change between versions:
module V2
class UsersController < V1::UsersController
def index
render json: User.all, only: [:id, :name, :email, :phone]
end
end
end
See references/strategies.md for a full URL path vs. Accept header comparison.
Define the Deprecatable concern to emit Sunset and Deprecation response headers. The inline implementation below is the canonical reference; a copy also lives in app/controllers/concerns/deprecatable.rb.
# app/controllers/concerns/deprecatable.rb
module Deprecatable
extend ActiveSupport::Concern
included do
before_action :set_deprecation_headers
end
private
def set_deprecation_headers
sunset_date = self.class.sunset_date
response.set_header("Deprecation", "true")
response.set_header("Sunset", sunset_date.httpdate) if sunset_date
Rails.logger.warn "[DEPRECATED] #{controller_path}##{action_name} called — sunset: #{sunset_date}"
end
class_methods do
def sunset_date
nil # Override per controller, e.g.: -> { Date.new(2025, 6, 1) }
end
end
end
Include it in any controller version due for retirement:
module V1
class UsersController < ApplicationController
include Deprecatable
# ...
end
end
After adding a new version, always run the backward compatibility suite before merging:
bundle exec rspec spec/requests/api/backward_compatibility_spec.rb
All existing v1 contract tests must remain green; a new version should never silently break prior consumers.
See EXAMPLES.md for complete code including:
See references/strategies.md for URL path vs header versioning comparison.