Sinatra是一个以最小的消耗快速创建Ruby web应用的DSL。
# myapp.rb
require 'sinatra'
get '/' do
'Hello world!'
end
安装gem:
gem install sinatra
然后运行
ruby myapp.rb
推荐也运行gem install thin,如果可用的话Sinatra会优先选择thin。
路由
在Sinatra中,一个路由是一个HTTP方法与URL匹配范式的配对。 每个路由都与一个代码块关联:
get '/' do
.. show something ..
end
post '/' do
.. create something ..
end
put '/' do
.. replace something ..
end
patch '/' do
.. modify something ..
end
delete '/' do
.. annihilate something ..
end
options '/' do
.. appease something ..
end
link '/' do
.. affiliate something ..
end
unlink '/' do
.. separate something ..
end