Grape和Sinatra结合使用

Grape && Sinatra

Grape(https://github.com/intridea/grape) is a REST-like API micro-framework for Ruby

Sinatra(http://www.sinatrarb.com/intro.html) is a DSL for quickly creating web applications in Ruby

可见,Grape适合构建纯Api系统,而Sinatra适合搭建web应用。

那么问题来了

如何将Grape和Sinatra融合到一起,取两者之长?

解决方案

# content.rb

class API < Grape::Api get '/' do 'lets go drinking!' end end class Web < Sinatra::Base get '/' do 'Lets go dancing!' end end # config.ru map '/' do run API end map '/web' do run Web end 

参考文档:http://stackoverflow.com/questions/15102293/sinatra-and-grape-api-together

你可能感兴趣的:(Sinatra)