Skip to content

Instantly share code, notes, and snippets.

@sent-hil
Created August 21, 2012 21:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sent-hil/3419815 to your computer and use it in GitHub Desktop.
Save sent-hil/3419815 to your computer and use it in GitHub Desktop.
River (getriver.com): HaProxy rules that matches based on api versions, http verbs and paths.
frontend http
  bind *:8000

  # match http verbs
  acl is_post method POST

  # match api versions
  acl one hdr(Accept) -i application/v0.1
  acl two hdr(Accept) -i application/v0.2

  # match paths
  acl users_create path_reg ^/users/create/?

  use_backend users_create_one if users_create one is_post
  use_backend users_create_two if users_create two

backend users_create_one
  server srv0 127.0.0.1:8100 weight 1 maxconn 200

backend users_create_two
  server srv2 127.0.0.1:8200 weight 1 maxconn 200
# Original idea was to redirect from Ruby like this:
#
# See https://groups.google.com/forum/#!topic/goliath-io/2ZboiYK_otc

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.constantize::Hello.call(env)
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment