Better way to create versioned web service?

Hello,

I want to create a web service which is “versioned”, which means each
version will have it’s own api and controller.

Ideally my directory structure would look like:
apis
1.00
webservice_api.rb
controllers
1.00
webservice_controller.rb

I also wanted to have a pretty URL like:
http://address.com/WebService/1.00/service.wsdl

The solution I managed to hack, is by modifying the following rails
files:


action_controller/routing.rb (line 228):

def traverse_to_controller(segments, start_at = 0)
mod = ::Object
length = segments.length
index = start_at
mod_name = controller_name = segment = nil

      # right now the version is hard coded, so it will check for 

version, and set global variable
if(segments[1] == ‘1.00’)
$controller_version = ‘1.00’
end

action_web_service/container/action_controller_container.rb (line 64):

if $controller_version != ‘’ && file_name != ‘application_api’
require_dependency($controller_version + ‘\’ + file_name)
else
require_dependency(file_name)
end


Then I created a file:
app/controllers/webservice_controller.rb

With the following:
require_dependency $controller_version + ‘/icuws_main_controller’


Those who managed to follow me :slight_smile: I am wondering if there is a better
solution to this problem, or my solution might benefit someone who needs
same kind of hack.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs