I'm working on a Rails app that uses grape
for its API. Currently, there's a single version of the API that is mounted in the root folder (not v1
, as I would like), and I need to start creating v2
. The current version is mounted as follows:
/app/api/api.rb
:
module API
class Base < Grape::API
logger Rails.logger
mount API::Things => '/things'
end
and then I have /app/api/api/things.rb
with something like:
module API
class Things < Grape::API
get '/' do
end
end
end
Basically, the API is mounted in /api/things
with a hardcoded path. I need to:
- Make this API the
v1
without changing its path. - Create a
v2
path.
So, I changed api.rb
to be:
module API
class Base < Grape::API
mount API::V1::Base
mount API::V2::Base
end
end
and created api/api/v1/base.rb
as follows:
module API
module V1
class Base < Grape::API
version 'v1', using: :accept_version_header
mount API::Things => '/things'
end
end
end
and then the same for v2
:
module API
module V2
class Base < Grape::API
version 'v2'
mount API::V2::Things => '/things'
end
end
end
My problem is that /things
does not inherit the /v2
path component as I would expect. Therefore, since v1
is mounted in /things
, v2
fails to mount there.
If I write v2
to use resources
instead of paths as v1
is, it works, but I'd like to keep the mounts as is, to make v2
consistent with v1
.