Skip to content

Instantly share code, notes, and snippets.

Created August 14, 2012 08:51
Show Gist options
  • Select an option

  • Save anonymous/3347608 to your computer and use it in GitHub Desktop.

Select an option

Save anonymous/3347608 to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Aug 14, 2012.
    31 changes: 31 additions & 0 deletions api_versions.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    # 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