Created
March 14, 2013 13:25
-
-
Save Neil-Aframe/5161270 to your computer and use it in GitHub Desktop.
Example, non-working, attempt to use nesteed mounts in Grape for DRY design with multiple paths to same resources
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "grape" | |
# Example attempt to do nested mounting. The real-world case is for a resource which can be | |
# addressed in multiple ways, and I want a DRY design where groups define the parameters to address | |
# an item, but the manipulations possible are the same, and defined by the http verb, so should be | |
# in one place (class Thing in this example to read a "thing" resource) | |
class Thing < Grape::API | |
get do | |
{ :message => 'You found the thing!' } | |
end | |
end | |
class Things < Grape::API | |
group :by_name do | |
mount Thing | |
end | |
group :by_id do | |
mount Thing | |
end | |
end | |
class MainService < Grape::API | |
prefix 'api' | |
version 'v2' | |
format :json | |
rescue_from :all | |
group :things do | |
mount Things | |
# This isn't necessary for the example, just demonstrates that this is otherwise valid Grape code | |
get do | |
[:by_id, :by_name] | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment