grape
grape copied to clipboard
Nested Resources
Is there a way to have nested resources to get routes like this:
foo id bar id
| |
/foo/:id/bars/:id
Something along those lines:
resource :foo do
resource :bar do
get '/:id' do
#...this obviously misses the foo id
That would make it easy to map (model) relations to the API.
I don't believe this is currently supported. It looks like resource is just an alias to namespace: https://github.com/intridea/grape/blob/master/lib/grape/api.rb#L214
@bmorton is correct. The proper way to do this in grape is simply to declare a namespace (or use the just-committed segment alias):
resource :foo
segment '/:foo_id' do
resource '/bar' do
get '/:id' do
# this has :foo_id and :id set
end
end
end
end
@mbleigh could you point out where exactly the code that supports this type of nesting?