2

I've got a project running using Rails 2.3.14 and Ruby 1.8.7. I'd like to implement a versioning system for our RESTful API similar to what is shown in http://railscasts.com/episodes/350-rest-api-versioning.

I am finding some difficulties translating this to a Rails 2.x project. In particular, the scoped modules with constraints and defaults used to set up the routing:

namespace :api, defaults: {format: 'json'} do
  scope module: :v1, constraints: ApiConstraints.new(version: 1) do
    resources :products
  end
  scope module: :v2, constraints: ApiConstraints.new(version: 2, default: true) do
    resources :products
  end
end

Is there anything I can do to get the same behaviour in Rails 2? Ideally this would keep this versioning information in the headers, but I could also live with a solution where its maintained in the url (../api/v1/...), as long as the exclusion of a version number could also be routed to the default version. For example, if the API is at version 2, then /api/users should route to the same location as /api/v2/users, while still allowing older versions to be accessed by specifying the version (ie, /api/v1/users still routes to version 1 of the API).

Thanks,

Simon

0 Answers0