ITeye博客

Grape和Sinatra结合使用

Goldice · 2015-07-23 23:36 · Linux和开源软件 · 编程语言 · Markdown

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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。