I have two simple API classes:
class API::Root < Grape::API
version 'v1', :using => :path
mount API::Appointments => '/appointments'
end
and
class API::Appointments < API::Base
get do
end
end
The issue is that API::Appointments
generates route:
GET /appointments/v1
as opposed to
GET /v1/appointments
Is this how it's suppose to be? What am I doing wrong? Shouldn't version path component be before any other path component as oppose to in the end?
Thanks
From the example you gave, your resource file (appointments) is inheriting from the root.rb file, which uses a
:path
to get the version. Additionally, you are mounting to a path by usingmount API::Appointments => '/appointments'
, this acts much like a prefix and thus will prefix your routes with/appointments
, so the routes you are seeing are expected given your set up. When I version a JSON api using Grape, I have a base root.rb class which will mount my versioned APIs.Then for each additional API version, I have another root.rb file which then mounts the resource files for that particular API.
With this structure you can have a resource class
and it will be mounted to the route
/v1/appointments