1

I am trying out goliath non-blocking ruby server.

For my application I need to make at least 2 defined routes, lets say "/call_one" and "/call_two", each map should respond in a different manner.

Goliath documentation mentions map function which is exactly what I need. But it no longer exists in source.

wael34218
  • 4,860
  • 8
  • 44
  • 62

2 Answers2

0

Indeed, it was removed, but you don't really need it. You can either install and run a generic mapper gem (having in mind that Goliath is pretty much rack compatible), like https://github.com/joshbuddy/http_router

Or you can just check the environments variable to see what RACK gives you and do the right routing, like

class MyServer < Goliath::API    
  def response(env)
    case env['PATH_INFO']
      when '/action_1'
        [200, {}, "Action 1 Response"]
      when '/action_2'
        [200, {}, "Action 2 Response"]
      when '/'
        [200, {}, "Root Action"]
      else
        raise Goliath::Validation::NotFoundError
    end
  end
end
rorra
  • 9,593
  • 3
  • 39
  • 61
0

The router was removed from Goliath as there are a lot of tricky edge cases that it caused. The original intent of Goliath was one route, one API. So, we'd have either Nginx or HAProxy in front that would route to the correct Goliath API server (typically a bunch of Goliath servers for each route).

For us, this was the best solution as it allowed us to updated any API server without effecting any of the others.

dj2
  • 9,534
  • 4
  • 29
  • 52