[Sinatra][ruby]
Sinatraはお手軽らしいので、どんだけお手軽かみてみる。
0 # hoge.rb 1 require 'rubygems' 2 require 'sinatra' 3 4 get '/' do 5 "Hello World!" 6 end
ruby hoge.rb
あ、立ち上がった。
[2009-09-08 22:35:40] INFO WEBrick 1.3.1 [2009-09-08 22:35:40] INFO ruby 1.8.7 (2008-08-11) [i486-linux] [2009-09-08 22:35:40] INFO WEBrick::HTTPServer#start: pid=21923 port=4567 127.0.0.1 - - [08/Sep/2009 22:35:46] "GET / HTTP/1.1" 200 12 0.0008 localhost - - [08/Sep/2009:22:35:46 JST] "GET / HTTP/1.1" 200 12
GETしてみる
GET http://localhost:4567/
かえってきた
Hello World!
すげーらくだ
あと、こんな真似もできるし
get %r{/hello/([\w]+)} do "Hello, #{params[:captures].first}!" end
あと、
In Sinatra, a route is an HTTP method paired with an URL matching pattern. Each route is associated with a block:
というわけで、HTTPの各メソッドをサポートしてる。(うれしいのかどうかしらんけどw
post '/' put '/' put '/' delete '/' ... ||> http://www.sinatrarb.com/ http://www.ruby-lang.org/ja/man/html/WEBrick_HTTPServer.html