class MyAPI < Grape::API
resource configuration[:path] || :integration_links do
nested = configuration[:nested]
desc "Retrieve blah for #{nested}" do
detail <<~NOTE
Returns a collection of blah for #{nested}
NOTE
end
get do
p = declared(params)
case configuration[:nested] # was options[:for].configuration[:nested] for v1.2.3
when :project
when :integration
else
raise ArgumentError, 'Endpoint mounted incorrectly'
end
end
end
end
I have this specific "endpoint" mounted 2 times
(inside my integrations endpoints)
mount Resources::IntegrationProjectLinks, with: {nested: :integration, path: :project_links}
(Inside my Projects endpoints)
mount Resources::IntegrationProjectLinks, with: {nested: :project}
We have many other endpoints that are mounted multiple times. e.g. a "Tasks" that is mounted 3 times. Once under project, once under orgs, and once at the root (for shallow) w/o any with: {} params.
class Tasks < Grape::API
resource :tasks do
nested = configuration[:nested]
if configuration[:nested].present?
desc "retreive tasks for #{nested}"
params do
use :user_ids_filter
end
get do
case configuration[:nested]
when :organization
scope = org_scope
when :project
scope = project_scope
else
raise ArgumentError, 'Endpoint mounted incorrectly'
end
# rest of logic + present
end
end
end
end
class Project < Grape::API
resource :projects do
nested = configuration[:nested]
if configuration[:nested]
# nested routes
get do
end
else
# shallow routes
params do
requires :project_id, type: Integer
end
resource ':project_id' do
# shallow get/update/etc.
mount Resources::Tasks, with: {nested: :project}
end
end
end
end
My question is.. All of this seems to work fine on Grape 1.3.x so far (we have many other things we are fixing in the upgrade to grape 1.3.x still)
But the documentation seems to imply I should be using mounted/given.
So is there something I'm missing in the documentation as to when/why I should be using given/mounted?
--
You received this message because you are subscribed to the Google Groups "Grape Framework Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/badbda69-a05d-4fe6-ad48-b243c3f89790%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/badbda69-a05d-4fe6-ad48-b243c3f89790%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to ruby-grape+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/07cb861f-9ad5-4695-b49a-4b7ccb596e31%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ruby-grape/CALCE7pnJDQzNVxr6NLYH-9cPLV3f%2BK%3D1s77qhRxDeHgp%3D-_yOw%40mail.gmail.com.