nz52yw
Last Updated: February 15, 2018
·
722
· Irina

API Versioning with Ruby on Rails: What Gems Are the Best

Here’s an example of versioned routes from the versionist gem using the Accept Header with the versioned media type:

namespace :versionist_api do

api_version(

header: {

  name: "Accept",

  value:  'application/vnd.versionist_api.v2+json'

},

module: "V2",

defaults: { format: :json }

) do

resources :books, only: [:index, :create, :show, :update, :destroy]

end

api_version(

header: {

  name: 'Accept',

  value: 'application/vnd.versionist_api.v1+json'

},

module: 'V1',

default: true,

defaults: { format: :json }

) do

resources :books, only: [:index, :create, :show, :update, :destroy]

end

end

Full info: https://yalantis.com/blog/api-versioning-with-ruby-on-rails/