$ sudo gem install rack
hello.rb
require 'rubygems' require 'rack' class Hello def call(env) [200, {"Content-Type" => 'text/plain'},["Hello World!"]] end end
hello.ru
require 'hello' run Hello.new
実行(rack up)
$rackup hello.ru
http://localhost:9292/ へアクセス→ウマー
RequestとResponse
hello.rb
require 'rubygems' require 'rack' class Hello def call(env) req = Rack::Request.new(env) res = Rack::Response.new() res.status = 200 res["Content-Type"] = "text/plain" res.write( req.params.map{ |k, v| "#{k}=#{v}" }.join("\n") ) res.finish end end
rack upして http://localhost:9292/?hoge=1&fuga=2 へアクセス→ウマー
なるほど…。