I'm trying to version my API like Stripe has. Below is given the latest API version is 2.
/api/users
returns a 301 to /api/v2/users
/api/v1/users
returns a 200 of users index at version 1
/api/v3/users
returns a 301 to /api/v2/users
/api/asdf/users
returns a 301 to /api/v2/users
So that basically anything that doesn't specify the version links to the latest unless the specified version exists then redirect to it.
This is what I have so far:
scope 'api', :format => :json do scope 'v:api_version', :api_version => /[12]/ do resources :users end match '/*path', :to => redirect { |params| "/api/v2/#{params[:path]}" }end