RubyでWebアプリケーション : Web with Ruby
(1) CGI - IIS- 色々設定面倒
 
- httpd.confを修正
 
- 分かっていれば簡単。初めてだとちょっとはまる
 
- インストールは簡単。
 
- 機能豊富、仕掛けは大がかり、重たい。
 
sinatra on ruby
第4の選択肢: sinatra
シンプル、軽量なWebアプリケーションライブラリ- Rackという規格に従っている
 
- Model, Viewは好きなライブラリと組み合わせる
 
Installing sinatra
コマンドプロンプトから- set http_proxy=http://proxy:port       ※proxy越えの場合
 
- gem install sinatra
 
最初のsinatra
hello.rb
require "rubygems"require "sinatra"
get '/' do
"Hello, sinatra world"
end
コマンドプロンプトから
- ruby hello.rb
 
- http://localhost:4567/
 
sinatraとパラメータ
hello.rb
require "rubygems"Require "sinatra"
get '/' do
“Hello, sinatra world”
end
get '/:name' do
"Hello, #{params[:name]}!"
end
コマンドプロンプトから
- ruby hello.rb
 
- http://localhost:4567/foo
 
sinatraとREST
REST APIと相性が良い
get '/target' do“取得の処理”
end
post '/target' do
“生成(登録)処理”
end
put '/target' do
“更新処理”
end
delete '/target' do
“削除処理”
end
0 件のコメント:
コメントを投稿