Mount Controllers with Routing Namespace #14

Open
opened 2025-08-13 13:04:01 -04:00 by gballan · 1 comment
Owner

Right now all of the route controllers are mounted at the top-level "/" route, so all of their routes need to define their full route. e.g. /api/v1/result/list. Ideally each controller should be mounted in its own namespace and their routes defined relative to their mount.

I don't know if this is possible with Sinatra, but would improve readability IMO.

Right now all of the route controllers are mounted at the top-level "/" route, so all of their routes need to define their full route. e.g. `/api/v1/result/list`. Ideally each controller should be mounted in its own namespace and their routes defined relative to their mount. I don't know if this is possible with Sinatra, but would improve readability IMO.
gballan added the
bug
label 2025-08-13 13:04:01 -04:00
Author
Owner

Unfortunately, the map method that AI recommended is meant to be put in the config.ru file. This solution might work, but would make testing a bit more wonky. I'll want to see what other impact that change might have before making that change.

Another option could be to define a route prefix in each controller and make the routes concatenate that variable:

class BenchmarkController < BaseController

  ROUTE_PREFIX = '/benchmark'

  get "#{ROUTE_PREFIX}/list' do
    # things for the route
  end

end

Only issue with this is it would mean EVERY ROUTE would need to compute/concatenate their route, instead of just using a static string.

Unfortunately, the `map` method that AI recommended is meant to be put in the `config.ru` file. This solution might work, but would make testing a bit more wonky. I'll want to see what other impact that change might have before making that change. Another option could be to define a route prefix in each controller and make the routes concatenate that variable: ```ruby class BenchmarkController < BaseController ROUTE_PREFIX = '/benchmark' get "#{ROUTE_PREFIX}/list' do # things for the route end end ``` Only issue with this is it would mean EVERY ROUTE would need to compute/concatenate their route, instead of just using a static string.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: BitGoblin/game-data#14
No description provided.