Created
February 18, 2014 11:11
-
-
Save esebastian/9068949 to your computer and use it in GitHub Desktop.
Mount routes from extension in Sinatra
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
# add requires as needed... | |
# main app | |
class App < Sinatra::Base | |
register Sinatra::Namespace | |
# mount routes from extension | |
register Sinatra::Guides | |
mount_guides | |
# mount routes from extension inside a namespace | |
namespace '/tours' do | |
register Sinatra::Tours | |
mount_tours | |
end | |
get '/' do | |
{ say: "hello API" }.to_json | |
end | |
end | |
# modules | |
module Sinatra | |
module Tours | |
def mount_tours | |
get '/' do | |
{ say: "tours API" }.to_json | |
end | |
get '/add' do | |
{ add: "yeah" }.to_json | |
end | |
end | |
end | |
register Tours | |
module Guides | |
def mount_guides | |
get '/' do | |
{ say: "guides API" }.to_json | |
end | |
get '/add' do | |
{ add: "nope" }.to_json | |
end | |
end | |
end | |
register Guides | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment