Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Hypermedia APIs with Webmachine and ROAR
Search
Larry Staton Jr.
November 15, 2012
Technology
2
480
Hypermedia APIs with Webmachine and ROAR
Building hypermedia APIs with Webmachine and ROAR
Larry Staton Jr.
November 15, 2012
Tweet
Share
More Decks by Larry Staton Jr.
See All by Larry Staton Jr.
Object-Oriented Programming Basics with Smalltalk
statonjr
0
480
A Tale of Two Teams
statonjr
0
46
Hypermedia with Transit
statonjr
0
69
Hazel & Keyboard Maestro: A Perfect Mac Marriage
statonjr
1
690
Zooming Out
statonjr
0
55
HTTP 101
statonjr
1
230
PUT /time
statonjr
1
70
Other Decks in Technology
See All in Technology
データ活用促進のためのデータ分析基盤の進化
takumakouno
2
440
エンジニアが一生困らない ドキュメント作成の基本
naohiro_nakata
2
140
Microsoft MVPになる前、なってから/Fukuoka_Tech_Women_Community_1_baba
nina01
0
170
10分でわかるfreeeのQA
freee
1
3.5k
障害対応指揮の意思決定と情報共有における価値観 / Waroom Meetup #2
arthur1
3
270
Postmanの日本市場におけるDevRel (的) 活動 / Postman's DevRelish activities in Japan
yokawasa
1
120
製造現場のデジタル化における課題とPLC Data to Cloudによる新しいアプローチ
hamadakoji
0
210
20241108_CS_LLMMT
shigashiyama
0
250
利きプロセススケジューラ
sat
PRO
4
2.6k
元旅行会社の情シス部員が教えるおすすめなre:Inventへの行き方 / What is the most efficient way to re:Invent
naospon
2
280
SREの組織類型に応じた リーダシップの考察
kenta_hi
PRO
1
620
Terraform Stacks入門 #HashiTalks
msato
0
220
Featured
See All Featured
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
505
140k
Documentation Writing (for coders)
carmenintech
65
4.4k
Designing on Purpose - Digital PM Summit 2013
jponch
115
7k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
27
2k
Bash Introduction
62gerente
608
210k
The Cost Of JavaScript in 2023
addyosmani
45
6.7k
10 Git Anti Patterns You Should be Aware of
lemiorhan
654
59k
VelocityConf: Rendering Performance Case Studies
addyosmani
325
24k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
32
1.8k
Fashionably flexible responsive web design (full day workshop)
malarkey
404
65k
Bootstrapping a Software Product
garrettdimon
PRO
305
110k
Transcript
Hypermedia APIs Hypermedia APIs Webmachine & ROAR 1 Larry Staton
Jr. : @statonjr 1 Wednesday, 14 November 12
Hypermedia APIs Assumptions 2 2 Wednesday, 14 November 12
Hypermedia APIs REST 3 3 Wednesday, 14 November 12
Hypermedia APIs 4 Constraint Promotes Tradeoff client-server UI Portability Simplified
server stateless Scalability Reliability Efficiency non-shared caching Reduced latency Efficiency Scalability Reliability uniform interface Independent Evolution Decoupled implementation Efficiency layered system Scalability Simplified clients Higher Latency code-on-demand Extensibility Simplified clients Visibility 4 Wednesday, 14 November 12
Hypermedia APIs 5 Uniform Interface 5 Wednesday, 14 November 12
Hypermedia APIs HTTP 6 6 Wednesday, 14 November 12
Hypermedia APIs 7 Constraint Promotes Tradeoff client-server UI Portability Simplified
server stateless Scalability Reliability Efficiency non-shared caching Reduced latency Efficiency Scalability Reliability uniform interface Independent Evolution Decoupled implementation Efficiency layered system Scalability Simplified clients Higher Latency code-on-demand Extensibility Simplified clients Visibility 7 Wednesday, 14 November 12
Hypermedia APIs “REST APIs must be hypertext-driven” 8 — Fielding,
2009! 8 Wednesday, 14 November 12
Hypermedia APIs 9 Richardson Maturity Model 9 Wednesday, 14 November
12
Hypermedia APIs Hypermedia 10 10 Wednesday, 14 November 12
Hypermedia APIs Media Types 11 11 Wednesday, 14 November 12
Hypermedia APIs 12 Media Type Hypermedia? text/html application/atom+xml application/json application/hal+json
12 Wednesday, 14 November 12
Hypermedia APIs HTTP 13 13 Wednesday, 14 November 12
Hypermedia APIs 14 14 Wednesday, 14 November 12
Hypermedia APIs Webmachine 15 15 Wednesday, 14 November 12
Hypermedia APIs Resources 16 16 Wednesday, 14 November 12
Hypermedia APIs 17 class HomeResource < Webmachine::Resource def allowed_methods %W[GET]
end def expires Time.now + 2.weeks end def languages_provided [“en-us”] end end 17 Wednesday, 14 November 12
Hypermedia APIs 18 allow_missing_post? allowed_methods base_uri charsets_provided content_types_accepted content_types_provided create_path
delete_completed? delete_resource encodings_provided expires finish_request forbidden generate_etag is_authorized? is_conflict? known_content_type? known_methods language_chosen languages_provided last_modified malformed_request? moved_permanently? moved_temporarily? multiple_choices? options post_is_create? previously_existed? process_post resource_exists? service_available? uri_too_long? valid_content_headers? valid_entity_length? validate_content_checksum variances Callbacks 18 Wednesday, 14 November 12
Hypermedia APIs 19 Webmachine::Application.new do |app| app.routes do add [],
HomeResource end end 19 Wednesday, 14 November 12
Hypermedia APIs Representation 20 20 Wednesday, 14 November 12
Hypermedia APIs HTML 21 21 Wednesday, 14 November 12
Hypermedia APIs 22 <!DOCTYPE html> <html lang=”en”> <body> <a href=”...”
rel=”../vehicles”>Vehicles</a> </body> </html> Example HTML Representation 22 Wednesday, 14 November 12
Hypermedia APIs 23 class HomeResource < Webmachine::Resource … def content_types_provided
[[‘text/html’, :to_html]] end def to_html template = Slim::Template.new(“home_representer.slim”) template.render end end 23 Wednesday, 14 November 12
Hypermedia APIs HAL+JSON 24 24 Wednesday, 14 November 12
Hypermedia APIs 25 { “_links”: { “self”: { “href”: “.../api”
}, “vehicles”: { “href”: “.../vehicles” } } } Example HAL+JSON Representation 25 Wednesday, 14 November 12
Hypermedia APIs ROAR 26 26 Wednesday, 14 November 12
Hypermedia APIs 27 module HomeRepresenter include Roar::Representer::JSON include Roar::Representer::JSON::HAL include
Roar::Representer::Feature::Hypermedia link :self do "/api" end link :vehicles do ".../vehicles" end end 27 Wednesday, 14 November 12
Hypermedia APIs 28 class HomeResource < Webmachine::Resource … def content_types_provided
[[‘application/hal+json’, :to_hal]] end def to_hal home = Object.new.extend(HomeRepresenter) home.to_json end end 28 Wednesday, 14 November 12
Hypermedia APIs Next Steps 29 29 Wednesday, 14 November 12
Hypermedia APIs Conclusion 30 30 Wednesday, 14 November 12
Hypermedia APIs Questions? 31 31 Wednesday, 14 November 12
Hypermedia APIs Additional Resources 32 seancribbs/webmachine-ruby apotonick/roar Jon Moore’s 2010
Oredev talk Steve Klabnik: “Designing Hypermedia APIs” Mike Amundsen: “Building Hypermedia APIs” Webber/Robinson: “REST in Practice” RESTFest 32 Wednesday, 14 November 12