💎 Ruby on Rails
Intermediate
What is an API versioning strategy in Rails?
Answer
Common Rails API versioning approaches: URL versioning — /api/v1/users, /api/v2/users using namespaces: namespace :api do namespace :v1 do resources :users end end. Header versioning — version specified via Accept: application/vnd.myapi.v1+json header, parsed in the router or a base controller. Query parameter versioning — ?version=1. URL versioning is most widely used for its simplicity and cacheability. Create separate controller directories (app/controllers/api/v1/) and serializers per version to allow independent evolution without breaking clients.
Previous
What is the Rails router's namespace and scope?
Next
What are Rails concerns and when should you use them?