Skip to content

Instantly share code, notes, and snippets.

Created August 14, 2012 08:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/3347608 to your computer and use it in GitHub Desktop.
Save anonymous/3347608 to your computer and use it in GitHub Desktop.
# Problem: Divide api into version to provide a consistent experience to developers.
require 'goliath'
require 'active_support/all'
module V01
class Hello
def self.call(env)
[200, {}, {'response' => 'V01'}]
end
end
end
module V02
class Hello
def self.call(env)
[200, {}, {'response' => 'V02'}]
end
end
end
class HelloApp < Goliath::API
use Goliath::Rack::Params
def response(env)
version = env['HTTP_ACCEPTS'].tr('^0-9','')
version = "V"+version
version.to_s.constantize::Hello.call(env)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment