I have a simple server in Sinatra, like
require 'sinatra/base'
class Server < Sinatra::Base
get '/' do
"root"
end
get '/api/:apiname' do
"return api from module #{params.apiname}"
end
end
I want to be able to include modules for each api, which could use Sinatra DSL. It could be like:
module SomeApi
get '/api_method'
"result of api call"
end
end
Then I want to include SomeApi module to my Server class, to be able to get api call result from url “http://localhost/someapi/api_method”. Is it possible to change my code to be able to do this, or should I use another framework then Sinatra? Thanks a lot!
Maybe you will find the
mapmethod from Rack useful. With it, you could do something like:config.ru:
app.rb:
start server:
test it: