SlideShare a Scribd company logo
1 of 45
Ruby on Rails2.0 における REST 対応 丸山先生レクチャーシリーズ ~ RESTful サービス技術の台頭~ よういちろう 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
自己紹介 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
アジェンダ ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
アジェンダ ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
Ruby on Rails における REST ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. dispatcher.cgi routes.rb Controller View Model Database 呼び出す Controller を特定 O/R マッピング Model への操作と View の決定 HTML や XML のレンダリング ActionPack ActiveRecord
Ruby on Rails における REST ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
Ruby on Rails における REST ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
Ruby on Rails における REST ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 Rails 2.0  では REST がメインとなる
Ruby on Rails における REST 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
アジェンダ ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
RESTful サービスへのアクセス ,[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 Business Object ActiveResource RESTful WebService 普通の Object へのアクセス 透過的なプロキシとして機能する Object と REST リソースのマッピング
RESTful サービスへのアクセス ,[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 Business Object Active Resource RESTful WebService Object と REST リソースのマッピング Business Object Active Record Object と Database Entity のマッピング Database
RESTful サービスへのアクセス ,[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 emp = Employee.new emp.name = ‘yoichiro’ emp. save emp = Employee. find (13308) p emp.name  # => “yoichiro” emp = Employee. find (13308) emp. destroy Employee. delete (12345) emp = Employee. find (13308) emp.name = ‘yojiro’ emp. save 生成 検索 更新 削除
RESTful サービスへのアクセス ,[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 class Status <  ActiveResource::Base self. site  = ‘http:// [ ユーザ ID]:[ パスワード ]@ twitter.com’ self. logger  = Logger.new($stderr) end ActionResource::Base クラスを継承 site クラス変数にリソースの在り処を指定 リソース名をクラス名にする logger クラス変数に設定すると URL が見える HTTP BASIC 認証
RESTful サービスへのアクセス ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 >> s =  Status.find(‘show/485685072’) => #<Status:0xb58ad1 @prefix_options={}, @attributes={&quot;text&quot;=>&quot;ActiveResource43014743012343015643027143030643037443430306430271430310 ! &quot;, &quot;id&quot;=>&quot;485685072&quot;, &quot;source&quot;=>&quot;web&quot;,  &quot;created_at&quot;=>&quot;Mon Dec 10 06:42:46 +0000 2007&quot;}> >>  GET http://twitter.com:80/statuses/show/485685072.xml --> 200 OK (733b 0.34s) >> puts s.text ActiveResource でこのステータス取得をテスト! => nil
RESTful サービスへのアクセス 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. Person.find(:all) # => GET /people.xml Person.find(:all, :params => { :title => &quot;CEO&quot; }) # => GET /people.xml?title=CEO Person.find(:first, :from => :managers) # => GET /people/managers.xml Person.find(:all, :from => &quot;/companies/1/people.xml&quot;) # => GET /companies/1/people.xml Person.find(:one, :from => :leader) # => GET /people/leader.xml Person.find(:one, :from => &quot;/companies/1/manager.xml&quot;) # => GET /companies/1/manager.xml StreetAddress.find(1, :params => { :person_id => 1 }) # => GET /people/1/street_addresses/1.xml
RESTful サービスへのアクセス ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 マッシュアップが非常に簡単になる
RESTful サービスへのアクセス ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. link_to_remote &quot;Delete this post&quot;, :update => &quot;posts&quot;, :url  => post_url(@post),  :method => :delete , :html => { :class  => &quot;destructive&quot; } ヘルパーメソッドが method 指定をサポート <a class=&quot;destructive&quot; href=&quot;#&quot; onclick=&quot;new Ajax.Updater('posts', 'http://localhost:3000/employees/3', {asynchronous:true, evalScripts:true,  method:'delete' , parameters:'authenticity_token=' + encodeURIComponent('520fb86f42576048061a5c408604c52411df8841')}); return false;&quot;>Delete this employee</a>
RESTful サービスへのアクセス ,[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved.
アジェンダ ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
RESTful サービスの実装 ,[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 Scaffold Code EmployeesController Employee Model Views
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 $ jruby ./script/generate scaffold employee # GET /employees/1 # GET /employees/1.xml def show @employee = Employee.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml {render :xml => @employee} end end employees_controller.rb ActionController::Routing::Routes.draw do |map| map.resources :employees routes.rb
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 RESTTest scaffold を生成するだけ コーディングなし
RESTful サービスの実装 ,[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 routes.rb map.resources Controller ActiveRecord Database 規則に従って、 HTTP Method および PATH から呼び出す Controller を選定 各メソッド内で ActiveRecord によりリソースを取得・更新 処理結果を HTTP Status に、リソースを XML 形式に変換して返却
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 ActionController::Routing::Routes.draw do |map| map.resources :employees end EmployeesController のメソッド Verb Path Method Parameter GET /employees index GET /employees/1 show :id => 1 POST /employees create PUT /employees/1 update :id => 1 DELETE /employees/1 destroy :id => 1
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 map.resources :divs do |divs| divs.resources :employees end EmployeesController のメソッド リソースのネスト定義 より多段にすることも可能 Verb Path Method Parameter GET /divs/1/employees index :div_id => 1 GET /divs/1/employees/2 show :div_id => 1 :id => 2 POST /divs/1/employees create :div_id => 1 PUT /divs/1/employees/2 update :div_id => 1 :id => 2 DELETE /divs/1/employees/2 destroy :div_id => 1 :id => 2
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 def  index @employees = Employee.find(:all) respond_to do |format| format.html # index.html.erb format.xml  { render :xml => @employees } end end routes.rb によるマッピング 「 .xml 」なので、モデルの内容が XML 形式でレンダリングされる
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 format.xml  { render :xml => @employees } <?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> <employees type=&quot;array&quot;> <employee> <id type=&quot;integer&quot;>3</id> <name>Yoichiro Tanaka</name> </employee> ・・・ </employees> View を作らなくてもレンダリングされる
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 def  show begin @employee = Employee.find(params[:id]) respond_to do |format| format.html # show.html.erb format.xml { render :xml => @employee } end rescue ActiveRecord::RecordNotFound head :not_found end end routes.rb によるマッピング 「 .xml 」なので、モデルの内容が XML 形式でレンダリングされる リソースがない場合は 404 を返す
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 def  create @employee = Employee.new(params[:employee]) respond_to do |format| if @employee.save format.html { redirect_to(@employee) } format.xml { render :xml => @employee, :status => :created, :location => @employee } else ・・・ end routes.rb によるマッピング 新規作成処理の結果、 ステータスコードは 201 Location ヘッダはリソースの URI を返却する
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 def  update begin @employee = Employee.find(params[:id]) respond_to do |format| if @employee.update_attribute(params[:employee]) format.html { redirect_to(@employee) } format.xml { head :ok } else ・・・ rescue ActiveRecord::RecordNotFond head :not_found end end routes.rb によるマッピング 更新処理の結果、 ステータスコードは 200 を返却する リソースがない場合は 404 を返す
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 def  destroy begin @employee = Employee.find(params[:id]) @employee.destroy respond_to do |format| format.html { redirect_to(employees_url) } format.xml { head :ok } end rescue ActiveRecord::RecordNotFond head :not_found end end routes.rb によるマッピング 削除処理の結果、 ステータスコードは 200 を返却する リソースがない場合は 404 を返す
RESTful サービスの実装 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved.
RESTful サービスの実装 ,[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 routes.rb map.resources Controller ActiveRecord Database 規則に従って、 HTTP Method および PATH から呼び出す Controller を選定 各メソッド内で ActiveRecord によりリソースを取得・更新 atom.builder filter View で Atom Feed を構築して返却 リクエストの XML を params ハッシュに変換
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. atom_feed  do |feed| feed.title(&quot;My great blog!&quot;) feed.updated((@posts.first.created_at)) for post in @posts feed.entry(post) do |entry| entry.title(post.title) entry.content(post.body, :type => 'html') entry.author do |author| author.name(&quot;DHH&quot;) end end end end View ヘルパーを使う
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. def parse_request_xml if  /^applicationatomxml/.match( request.env[“CONTENT_TYPE”] ) xml = REXML::Document.new(request.raw_post) params[:post]  = { :title => xml.elements[“ entry/title ”].text :content => xml.elements[“ entry/content ”].text } end return true end 変換ロジックは自作する このメソッドを before フィルタとしておくと良い XML をパースして、各要素から params ハッシュに格納 request.format = Mime::ATOM  でも可
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. def create @post = Post.new( params[:post] ) @post.save respond_to do |format| format.atom  do headers[“Content-Type”] = “ application/atom+xml;type=entry” render :action => “show”, :status => :created, :location => post_url(@post) + “.atom” end end end parse_request_xml により params[:post] が利用可能 POST /posts.atom  により  format.atom  が対応 新規投稿処理の結果、 ステータスコードは 201 Location ヘッダはリソースの URI を返却する
RESTful サービスの実装 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. xml .instruct! xml.entry(“xml:lang” => “ja”, “ xmlns” => “http://www.w3.org/2005/Atom”) do |entry| entry.title(@post.title) entry.content(@post.body, :type => 'html') entry.author do |author| author.name(&quot;DHH&quot;) end end Builder::XmlMarkup を使って構築
アジェンダ ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
認証処理 ,[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved.
認証処理 ,[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. class ApplicationController < ActionController::Base before_filter :authenticate protected def authenticate if request.format ==  Mime::ATOM if user =  authenticate_with_http_basic  { |u, p| @account.authenticate(u, p) } @current_user = user else request_http_basic_authentication end else request からユーザ ID およびパスワードを取得して認証を実施 認証失敗時に再度ブラウザに認証情報送信を要求 AtomPub の場合
認証処理 ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 X-WSSE: UsernameToken Username=“yoichiro&quot;, PasswordDigest=&quot;ZCNaK2jrXr4+zsCaYK/YLUxImZU=&quot;, Nonce=&quot;Uh95NQlviNpJQR1MmML+zq6pFxE=&quot;, Created=&quot;2007-12-11T22:51:15Z&quot;
認証処理 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. require ‘base64’ def auth_wsse @@wsse_pattern ||= /^UsernameToken Username=&quot;([^&quot;]+)&quot;,PasswordDigest= &quot;([^&quot;]+)&quot;,Nonce=&quot;([^&quot;]+)&quot;,Created=&quot;([^&quot;]+)&quot;$/ if request.env['HTTP_X_WSSE'] && @@wsse_pattern =~ request.env['HTTP_X_WSSE'] username = $1 passwd = Base64.decode64($2) nonce = Base64.decode64($3) created = $4 return  username == ‘yoichiro‘ &&  Digest::SHA1.digest( nonce + created + ‘pass’)  == passwd else ・・・ end 正規表現により認証情報を取得 パスワードと付加情報から SHA1 ダイジェストを生成し比較 これも before フィルタとしておけば便利
認証処理 ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved.
まとめ ,[object Object],[object Object],[object Object],[object Object],[object Object],2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09 Rails 2.0  は RESTful に最適な環境

More Related Content

Viewers also liked

maven2+aptで楽々ドキュメント
maven2+aptで楽々ドキュメントmaven2+aptで楽々ドキュメント
maven2+aptで楽々ドキュメントYoichiro Tanaka
 
Where to meet pretties
Where to meet prettiesWhere to meet pretties
Where to meet prettiesCat Chen
 
如何组织一场Open Party
如何组织一场Open Party如何组织一场Open Party
如何组织一场Open PartyCat Chen
 
Chrome Extensionsから見るWebExtensions
Chrome Extensionsから見るWebExtensionsChrome Extensionsから見るWebExtensions
Chrome Extensionsから見るWebExtensionsYoichiro Tanaka
 
Xaml Tutorial By Allan
Xaml Tutorial By AllanXaml Tutorial By Allan
Xaml Tutorial By AllanCat Chen
 
JavaEdge第3回ライブセッション
JavaEdge第3回ライブセッションJavaEdge第3回ライブセッション
JavaEdge第3回ライブセッションYoichiro Tanaka
 
SocialWeb-Japan Vol.2 20090428
SocialWeb-Japan Vol.2 20090428SocialWeb-Japan Vol.2 20090428
SocialWeb-Japan Vol.2 20090428Yoichiro Tanaka
 
Fabryka Gwiazd - Muzyka i Technologia
Fabryka Gwiazd - Muzyka i TechnologiaFabryka Gwiazd - Muzyka i Technologia
Fabryka Gwiazd - Muzyka i TechnologiaRafal Mrzyglocki
 
知道你为什么找不到好工作吗?
知道你为什么找不到好工作吗?知道你为什么找不到好工作吗?
知道你为什么找不到好工作吗?Cat Chen
 
Introducing Asp.Net Ajax 4.0 Preview
Introducing Asp.Net Ajax 4.0 PreviewIntroducing Asp.Net Ajax 4.0 Preview
Introducing Asp.Net Ajax 4.0 PreviewCat Chen
 
Web 2.0 social innovation proposal
Web 2.0 social innovation proposalWeb 2.0 social innovation proposal
Web 2.0 social innovation proposalSoogyun Nam
 
JavaScript Patterns
JavaScript PatternsJavaScript Patterns
JavaScript PatternsCat Chen
 
메커니즘디자인(발표용)
메커니즘디자인(발표용)메커니즘디자인(발표용)
메커니즘디자인(발표용)Soogyun Nam
 
Chrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターンChrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターンYoichiro Tanaka
 
基于Silverlight的RIA架构及百度应用
基于Silverlight的RIA架构及百度应用基于Silverlight的RIA架构及百度应用
基于Silverlight的RIA架构及百度应用Cat Chen
 
Baidu Map API Introduction
Baidu Map API IntroductionBaidu Map API Introduction
Baidu Map API IntroductionCat Chen
 

Viewers also liked (18)

maven2+aptで楽々ドキュメント
maven2+aptで楽々ドキュメントmaven2+aptで楽々ドキュメント
maven2+aptで楽々ドキュメント
 
Where to meet pretties
Where to meet prettiesWhere to meet pretties
Where to meet pretties
 
如何组织一场Open Party
如何组织一场Open Party如何组织一场Open Party
如何组织一场Open Party
 
Chrome Extensionsから見るWebExtensions
Chrome Extensionsから見るWebExtensionsChrome Extensionsから見るWebExtensions
Chrome Extensionsから見るWebExtensions
 
KATALOG firmy Aram
KATALOG firmy AramKATALOG firmy Aram
KATALOG firmy Aram
 
Xaml Tutorial By Allan
Xaml Tutorial By AllanXaml Tutorial By Allan
Xaml Tutorial By Allan
 
JavaEdge第3回ライブセッション
JavaEdge第3回ライブセッションJavaEdge第3回ライブセッション
JavaEdge第3回ライブセッション
 
SocialWeb-Japan Vol.2 20090428
SocialWeb-Japan Vol.2 20090428SocialWeb-Japan Vol.2 20090428
SocialWeb-Japan Vol.2 20090428
 
Fabryka Gwiazd - Muzyka i Technologia
Fabryka Gwiazd - Muzyka i TechnologiaFabryka Gwiazd - Muzyka i Technologia
Fabryka Gwiazd - Muzyka i Technologia
 
知道你为什么找不到好工作吗?
知道你为什么找不到好工作吗?知道你为什么找不到好工作吗?
知道你为什么找不到好工作吗?
 
Introducing Asp.Net Ajax 4.0 Preview
Introducing Asp.Net Ajax 4.0 PreviewIntroducing Asp.Net Ajax 4.0 Preview
Introducing Asp.Net Ajax 4.0 Preview
 
Web 2.0 social innovation proposal
Web 2.0 social innovation proposalWeb 2.0 social innovation proposal
Web 2.0 social innovation proposal
 
JavaScript Patterns
JavaScript PatternsJavaScript Patterns
JavaScript Patterns
 
메커니즘디자인(발표용)
메커니즘디자인(발표용)메커니즘디자인(발표용)
메커니즘디자인(발표용)
 
Chrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターンChrome Extensionsの基本とデザインパターン
Chrome Extensionsの基本とデザインパターン
 
基于Silverlight的RIA架构及百度应用
基于Silverlight的RIA架构及百度应用基于Silverlight的RIA架构及百度应用
基于Silverlight的RIA架构及百度应用
 
Baidu Map API Introduction
Baidu Map API IntroductionBaidu Map API Introduction
Baidu Map API Introduction
 
Edumix présentation
Edumix présentationEdumix présentation
Edumix présentation
 

Similar to 丸山先生レクチャーシリーズ2007-2008

Ruby on Rails Tutorial Chapter5-7
Ruby on Rails Tutorial Chapter5-7Ruby on Rails Tutorial Chapter5-7
Ruby on Rails Tutorial Chapter5-7Sea Mountain
 
Struts2を始めよう!
Struts2を始めよう!Struts2を始めよう!
Struts2を始めよう!Shinpei Ohtani
 
Maiking RIA Apps by Ruby
Maiking RIA Apps by RubyMaiking RIA Apps by Ruby
Maiking RIA Apps by Rubyshozon
 
Spring data-rest-and-spring-cloud-contract
Spring data-rest-and-spring-cloud-contractSpring data-rest-and-spring-cloud-contract
Spring data-rest-and-spring-cloud-contractTakeshi Ogawa
 
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力ThinReports
 
ウェブアーキテクチャの歴史と未来
ウェブアーキテクチャの歴史と未来ウェブアーキテクチャの歴史と未来
ウェブアーキテクチャの歴史と未来Kazuho Oku
 
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみようAlfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみようTasuku Otani
 
20101106 ramaze発表
20101106 ramaze発表20101106 ramaze発表
20101106 ramaze発表Fukui Osamu
 
Sharding with sql alchemy
Sharding with sql alchemySharding with sql alchemy
Sharding with sql alchemyAkira Matsuzaki
 
最近のRails開発のはなし
最近のRails開発のはなし最近のRails開発のはなし
最近のRails開発のはなしYoichi Toyota
 
Hybrid serverless architecture using open whisk ibm cloud functions and istio...
Hybrid serverless architecture using open whisk ibm cloud functions and istio...Hybrid serverless architecture using open whisk ibm cloud functions and istio...
Hybrid serverless architecture using open whisk ibm cloud functions and istio...Tsuyoshi Hirayama
 
Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】
Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】
Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】WESEEKWESEEK
 
Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略takezoe
 

Similar to 丸山先生レクチャーシリーズ2007-2008 (20)

Ruby on Rails Tutorial Chapter5-7
Ruby on Rails Tutorial Chapter5-7Ruby on Rails Tutorial Chapter5-7
Ruby on Rails Tutorial Chapter5-7
 
Cubby 2008-09-06
Cubby 2008-09-06Cubby 2008-09-06
Cubby 2008-09-06
 
Struts2を始めよう!
Struts2を始めよう!Struts2を始めよう!
Struts2を始めよう!
 
Cubby 2006-08-23
Cubby 2006-08-23Cubby 2006-08-23
Cubby 2006-08-23
 
Maiking RIA Apps by Ruby
Maiking RIA Apps by RubyMaiking RIA Apps by Ruby
Maiking RIA Apps by Ruby
 
Spring data-rest-and-spring-cloud-contract
Spring data-rest-and-spring-cloud-contractSpring data-rest-and-spring-cloud-contract
Spring data-rest-and-spring-cloud-contract
 
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
Ruby向け帳票ソリューション「ThinReports」の開発で知るOSSの威力
 
ウェブアーキテクチャの歴史と未来
ウェブアーキテクチャの歴史と未来ウェブアーキテクチャの歴史と未来
ウェブアーキテクチャの歴史と未来
 
Aerospike deep dive LDTs
Aerospike deep dive LDTsAerospike deep dive LDTs
Aerospike deep dive LDTs
 
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみようAlfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
Alfresco勉強会#36 alfresco 5でカスタムREST APIを作ってみよう
 
20101106 ramaze発表
20101106 ramaze発表20101106 ramaze発表
20101106 ramaze発表
 
Sharding with sql alchemy
Sharding with sql alchemySharding with sql alchemy
Sharding with sql alchemy
 
最近のRails開発のはなし
最近のRails開発のはなし最近のRails開発のはなし
最近のRails開発のはなし
 
Hybrid serverless architecture using open whisk ibm cloud functions and istio...
Hybrid serverless architecture using open whisk ibm cloud functions and istio...Hybrid serverless architecture using open whisk ibm cloud functions and istio...
Hybrid serverless architecture using open whisk ibm cloud functions and istio...
 
Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】
Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】
Rails×React×TS で作るwebアプリ入門【weseek tech conf #10】
 
History api
History apiHistory api
History api
 
Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略Seasarプロジェクト徹底攻略
Seasarプロジェクト徹底攻略
 
Sendai.html5#2
Sendai.html5#2Sendai.html5#2
Sendai.html5#2
 
Lithium Labo #1
Lithium Labo #1Lithium Labo #1
Lithium Labo #1
 
Ruby開発者のためのHeroku入門
Ruby開発者のためのHeroku入門Ruby開発者のためのHeroku入門
Ruby開発者のためのHeroku入門
 

More from Yoichiro Tanaka

Navigate users from assistant app to android app
Navigate users from assistant app to android appNavigate users from assistant app to android app
Navigate users from assistant app to android appYoichiro Tanaka
 
みんなの知らないChrome appsの世界
みんなの知らないChrome appsの世界みんなの知らないChrome appsの世界
みんなの知らないChrome appsの世界Yoichiro Tanaka
 
Chromeウェブストア - Html5とか勉強会42
Chromeウェブストア - Html5とか勉強会42Chromeウェブストア - Html5とか勉強会42
Chromeウェブストア - Html5とか勉強会42Yoichiro Tanaka
 
Sun Tech Days 2007 Mash up
Sun Tech Days 2007 Mash upSun Tech Days 2007 Mash up
Sun Tech Days 2007 Mash upYoichiro Tanaka
 
体操競技のルール改正と今後の日本の方向性
体操競技のルール改正と今後の日本の方向性体操競技のルール改正と今後の日本の方向性
体操競技のルール改正と今後の日本の方向性Yoichiro Tanaka
 
世間の荒波を乗りこなせ!
世間の荒波を乗りこなせ!世間の荒波を乗りこなせ!
世間の荒波を乗りこなせ!Yoichiro Tanaka
 

More from Yoichiro Tanaka (10)

Navigate users from assistant app to android app
Navigate users from assistant app to android appNavigate users from assistant app to android app
Navigate users from assistant app to android app
 
みんなの知らないChrome appsの世界
みんなの知らないChrome appsの世界みんなの知らないChrome appsの世界
みんなの知らないChrome appsの世界
 
Chromeウェブストア - Html5とか勉強会42
Chromeウェブストア - Html5とか勉強会42Chromeウェブストア - Html5とか勉強会42
Chromeウェブストア - Html5とか勉強会42
 
Info scoop opensource
Info scoop opensourceInfo scoop opensource
Info scoop opensource
 
Yapc
YapcYapc
Yapc
 
JRuby on Rails
JRuby on RailsJRuby on Rails
JRuby on Rails
 
Sun Tech Days 2007 Mash up
Sun Tech Days 2007 Mash upSun Tech Days 2007 Mash up
Sun Tech Days 2007 Mash up
 
体操競技のルール改正と今後の日本の方向性
体操競技のルール改正と今後の日本の方向性体操競技のルール改正と今後の日本の方向性
体操競技のルール改正と今後の日本の方向性
 
Wicket勉強会2
Wicket勉強会2Wicket勉強会2
Wicket勉強会2
 
世間の荒波を乗りこなせ!
世間の荒波を乗りこなせ!世間の荒波を乗りこなせ!
世間の荒波を乗りこなせ!
 

丸山先生レクチャーシリーズ2007-2008

  • 1. Ruby on Rails2.0 における REST 対応 丸山先生レクチャーシリーズ ~ RESTful サービス技術の台頭~ よういちろう 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. Ruby on Rails における REST 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. 05/29/09
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16. RESTful サービスへのアクセス 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. Person.find(:all) # => GET /people.xml Person.find(:all, :params => { :title => &quot;CEO&quot; }) # => GET /people.xml?title=CEO Person.find(:first, :from => :managers) # => GET /people/managers.xml Person.find(:all, :from => &quot;/companies/1/people.xml&quot;) # => GET /companies/1/people.xml Person.find(:one, :from => :leader) # => GET /people/leader.xml Person.find(:one, :from => &quot;/companies/1/manager.xml&quot;) # => GET /companies/1/manager.xml StreetAddress.find(1, :params => { :person_id => 1 }) # => GET /people/1/street_addresses/1.xml
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.
  • 34.
  • 35.
  • 36.
  • 37.
  • 38.
  • 39.
  • 40.
  • 41.
  • 42.
  • 43. 認証処理 2007/12/18 (c) 2007 Yoichiro Tanaka. All rights Reserved. require ‘base64’ def auth_wsse @@wsse_pattern ||= /^UsernameToken Username=&quot;([^&quot;]+)&quot;,PasswordDigest= &quot;([^&quot;]+)&quot;,Nonce=&quot;([^&quot;]+)&quot;,Created=&quot;([^&quot;]+)&quot;$/ if request.env['HTTP_X_WSSE'] && @@wsse_pattern =~ request.env['HTTP_X_WSSE'] username = $1 passwd = Base64.decode64($2) nonce = Base64.decode64($3) created = $4 return username == ‘yoichiro‘ && Digest::SHA1.digest( nonce + created + ‘pass’) == passwd else ・・・ end 正規表現により認証情報を取得 パスワードと付加情報から SHA1 ダイジェストを生成し比較 これも before フィルタとしておけば便利
  • 44.
  • 45.