1 year ago
#218513
anz
Redirect /api/v1 to /api/v2 in Rails 6
I have a Rails 6 app, where I am upgrading some functionalities and upgrading the API version to v2
. There are older clients out there that are using the v1
API versions. For all these, I have to change the incoming url in v1
to v2
.
Example,
a request comes in at /api/v1/users
, I want it to change to /api/v2/users
.
I've tried few things like using redirect
in routes.rb
file, like the ones suggested in API Versioning for Rails Routes. However, I could not get it too work.
My routes.rb file contains something like this:
Rails.application.routes.draw do
namespace 'ads' do
get '/fingerprint' => 'fingerprint#index'
end
namespace 'api' do
scope '/v2' do
...
end
end
end
I'd like to add something like
namespace 'api' do
scope '/v1' do
# redirect to v2 version of the url
end
scope '/v2' do
...
end
end
I'd like to fix it within the Rails app, but I guess fixing at Apache is also an option. I'm open to any sorts of solutions. Thanks.
ruby-on-rails
ruby
apache
ruby-on-rails-6
api-versioning
0 Answers
Your Answer