Upload
yohei-yamamoto
View
5.775
Download
0
Embed Size (px)
Citation preview
REST 信者から見たRuby on Rails 2.0
山本陽平
YAMAMOTO Yohei
REST 信者から見たRuby on Rails 2.1
山本陽平
YAMAMOTO Yohei
REST 信者から見たRuby and Rails
山本陽平
YAMAMOTO Yohei
自己紹介Who am I
• ソフトウェアエンジニア– Software Engineer
• XML 野郎– XML guy
• REST 信者– RESTian
• ルビー初心者– JavaからRubyへ– Ruby beginner
– from Java to Ruby
自慢I’m very proud for…
Ruby スポン
サーな会社で働いています
I’m working in Ruby
sponsor company
今日の話題
Today’s theme is…
REST と Ruby とRails について
About REST and Ruby and Rails
まずは…
First…
REST と Ruby について
About REST and Ruby
REST と Ruby は仲良し
REST and Ruby are good friends
ruby-dev におけるRESTの議論
REST discussion in ruby-dev
REST と Ruby は仲良し
REST and Ruby are good friends
REST と Rails も仲良し
REST and Ruby are also friends
REST と Rails は仲良し
REST and Rails are good friends
REST
Representational State Transfer
REST
• Web のアーキテクチャスタイル
– Web Architectural style
• 制約の集合
– Set of constrains
– ULCODC$SS
抽象化レベルAbstraction Level
• Implementaion
– Apache, Rails, Firefox, bot
• Architecture
– User Agent, Server, HTTP, URI, HTML
• Architectural Style
– Constrains, Styles
リソース指向アーキテクチャ
Resource Oriented Architecture
ROA の四つの構成要素Four features of the ROA
• (A) アドレス可能性– Addressability
• (S) ステートレス性– Statelessness
• (C) 接続性– Connectedness
• (U) 統一インターフェース– A Uniform Interface
A > C > U >>>>>>>>>S
アドレス可能性>接続性>統一インターフェース>>>>>>>>>>ステートレス性
Addressability > Connectedness > A Uniform Interface>>>>>>>>> Statelessness
ROA の四つの構成要素Four features of the ROA
• (A) アドレス可能性– Addressability
• (S) ステートレス性– Statelessness
• (C) 接続性– Connectedness
• (U) 統一インターフェース– A Uniform Interface
アドレス可能性
Addressability
アプリケーションがそのデータセットの重要な部分をリソースとして公開する場合、そのアプリケーションはアドレス可能である。
An application is
addressable if it exposes
the interesting aspects of
the data set as resources.
リソースは URI を通じて提供される
ため、アドレス可能なアプリケーションは提供可能な情報ごとにURI を公開する。
Since resources are exposed
through URIs, an addressable
application exposes a URI for
every piece of information it
might conceivably serve.
リソース/URI 駆動開発
Resource/URI driven development
URI の設計↓
URI の実装
Design URI → Implement URI
URIの設計
URI design
Blog entries list resource
/entries
(GET/POST)
Blog entry resource
/entries/{entry_id}
(GET/PUT/DELETE)
URIの実装
URI implementation
map.resources :entries
シンプルだけど…
It’s simple, but…
Rails のルーティングは
素晴らしいが、コードの構造に依存しがち
Routing of Rails is good, but
code structure dependent
URIは設計目標であって実装結果ではない
URIs are design goal,
not implementation result
Restlet
router.attach(“/entries”,EntryListResource.class);
router.attach(“/entries/{id}”,EntryResource.class);
Django
urlpatterns = patterns((r’^entries/$’, entry_list),(r’^entries/([¥w-]+)/$’, entry_detail),
)
接続性Connectedness
現在のページ == アプリケーション状態
Current Page = Application State
ハイパーメディアを設計== アプリケーションを設計
Design hypermedia
== design application
ハイパーメディアを設計== リソースとリンクを設計
Design hypermedia
== design resources and links
リンクの設計
Link design
リンクの実装
Link implementation
url_for
link_to
シンプルだけど…
It’s simple, but…
リンクの意味を意識できればもっといい
Semantics of a link is important
続きは WEB+DB
PRESS Vol. 45 で
まとめ
Conclusion
実際のところ Rails
は RESTful である
Actually, Rails is RESTful
アドレス可能性と
接続性でよりよい設計を
A better design by
addressability and connectedness