SlideShare a Scribd company logo
1 of 29
Download to read offline
Reviewing
RESTful Web Apps
Takuto Wada (a.k.a id:t-wada or @t_wada)
Apr 12, 2014 @ RESTful Meetup
Takuto Wada
id: t-wada
@t_wada
github: twada
tl;dr:
REST is
infection
(Use it, love it, but think carefully.)
•WEB+DB PRESS vol.32
•Discussion around Hatena-Bookmark
•RubyKaigi 2006 Keynote by DHH
•WEB+DB PRESS vol.38
•RESTful Web Service
•RESTful Web APIs
REST and me (input)
•Java implementations (S2REST)
•WEB+DB PRESS vol.42 Experiencing
REST world with Restlet
• Practical REST talk series by gihyo
• #restwebtech book talk session
REST and me (output)
•Large Rails Project
•+1000 routes
•Tools for reviewing
•White board
•Chat (IRC, Skype, ...)
•Wiki
•diff
Target Project
1. Figure out the data set
2. Split the data set into resources
For each kind of resource:
3. Name the resources with URIs
4. Expose a subset of the uniform interface (GET/POST/PUT/DELETE)
5. Design the representation(s) accepted from the client
6. Design the representation(s) served to the client
7. Integrate this resource into existing resources, using hypermedia
links and forms (Connectedness matters)
8. Consider the typical course of events: what s supposed to happen?
9. Consider error conditions: what might go wrong?
Turning Requirements into Resources
•URL Design (verb, structure, query
params)
•fighting with the gravity of CRUD
•HTTP method
•HTTP status code
•Representation
•MECE of information
•Connectedness
Review point
Bad GET http://example.com/blog/getEntries
Good GET http://example.com/blog/entries
Bad POST http://example.com/blog/entries/add
Good POST http://example.com/blog/entries
Bad POST http://example.com/blog/entries/30/delete
Good DELETE http://example.com/blog/entries/30
Do not include verbs in URL
•/add, /delete, /update => Bad
•/edit => it depends (convention matters)
•Trying to use nouns
•/confirm -> /confirmation
•When the form of noun and verb are the
same => it depends
Do not include verbs in URL
• Tumblr s Bizarre URL => Too Bad
• http://www.tumblr.com/show/everything/by/me
• Reads like spoken language doesn t matter
• example.com/files/copy/:src/:dest => Bad
• destination is not subordinated to source
• Are they natural subordinates/subsets ?
Is your URL natural?
• URL Design is about searching for good names
• standard names (microformats, W3C, ...)
• dictionary, thesaurus, ...
• Find the third resource , the resource representing
relationship between resources.
• subscription, participation, ...
• Finally, ing s. belonging, tagging, ...
Searching for names
• What is it? => Meaning
• How do I get it? => Will
• Meaning shouldn t change even if query
parameters are removed.
• URL fragments should be composed of
meaningful names.
Meaning and Will in URL
http://example.com/blog/entries?page=3&lang=ja
Meaning of the Resource Will of client
• Resources are not only Database Records.
• Transactions
• Calculation Results
• Search Results
Resources ≠ Database Records
•Simple and automatic mapping looks nice
•GET/POST/PUT/DELETE
•SELECT/INSERT/UPDATE/DELETE
•It s a trap!
The Gravity of CRUD
•Why trap?
•Importance of models/tables varies.
•Core Domain Models tend to have many
more meanings and representations.
•In contrast, some tables are just
dependent tables. So they don t have
their own representations.
The Gravity of CRUD
•Don t just map 3NF tables to resources
•Some of them are too fine-grained
•N+1 Problem appears!
•Routes and Controllers should:
•Fill the gap of granularity and viewpoint
between Resources and Tables.
•Map them if and only if it is meaningful.
The Gravity of CRUD
•What do you want to do to the Resource?
•get it => GET
•create new one => POST
•modify it => UPDATE / PATCH
•delete it => DELETE
HTTP Methods
•Contents is the king and so HTTP GET is
the king.
•To make Resources:
•new Resource with new URL => POST
•URL is known/given => PUT
•If in doubt, use POST
HTTP Methods
•Status codes regularly used
•200, 201, 204
•301, 303, 307, (304)
•400, 404, 409, (401, 403, 422 (rails))
•500
•Client is wrong => 4xx
•Server is wrong => 5xx
HTTP Status Code
•Mapping Errors to 4xx or 5xx
•Models just raise Errors
•Rails maps them
•Want to hide resources => use 404
HTTP Status Code
•Should contain URL or URL
creator(forms)
•No dead-ends
•If you want to construct GET query
parameters
•use forms
•forms are not only for POST
requests
Representation
•Content Negotiation
•use Accept, Accept-Language
•Better to include representation
formats in URL (fragments,
extensions)
•more better to include languages
(ja,en,...) in URL
Representation
•Don t concat strings to create URL on
the client side!
•Client shouldn t know how to
construct URLs
•use URI-Templates
•http://tools.ietf.org/html/rfc6570
Representation
•Client can only change its
application status by
following links (or submitting
forms) in representations
served by servers
For the Connectedess
•Services should not enforce clients to
construct URL
•Services should not expect clients to
construct URL
•Services should serve representations
with links(forms) for next application
state transitions
For the Connectedess
References
tl;dr:
REST is
infection
(Use it, love it, but think carefully.)
Thanks!
http://lumberjaph.net/graph/2010/03/25/github-explorer.html

More Related Content

What's hot

Library Mashups & APIs
Library Mashups & APIsLibrary Mashups & APIs
Library Mashups & APIs
librarywebchic
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
Hal Stern
 
Harnessing Free Content with Web Service APIs
Harnessing Free Content with Web Service APIsHarnessing Free Content with Web Service APIs
Harnessing Free Content with Web Service APIs
ALATechSource
 

What's hot (20)

flickr's architecture & php
flickr's architecture & php flickr's architecture & php
flickr's architecture & php
 
Austin Day of Rest - Introduction
Austin Day of Rest - IntroductionAustin Day of Rest - Introduction
Austin Day of Rest - Introduction
 
Ebook Accessibility: Why, How, and What For - ebookcraft 2016 - Laura Brady
Ebook Accessibility: Why, How, and What For - ebookcraft 2016 - Laura BradyEbook Accessibility: Why, How, and What For - ebookcraft 2016 - Laura Brady
Ebook Accessibility: Why, How, and What For - ebookcraft 2016 - Laura Brady
 
Creating Truly RESTful APIs
Creating Truly RESTful APIsCreating Truly RESTful APIs
Creating Truly RESTful APIs
 
RESTful Web Services
RESTful Web ServicesRESTful Web Services
RESTful Web Services
 
On Again; Off Again - Benjamin Young - ebookcraft 2017
On Again; Off Again - Benjamin Young - ebookcraft 2017On Again; Off Again - Benjamin Young - ebookcraft 2017
On Again; Off Again - Benjamin Young - ebookcraft 2017
 
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
You Want to Go XML-First: Now What? Building an In-House XML-First Workflow -...
 
Library Mashups & APIs
Library Mashups & APIsLibrary Mashups & APIs
Library Mashups & APIs
 
Front End Web Development Basics
Front End Web Development BasicsFront End Web Development Basics
Front End Web Development Basics
 
In the Trenches with Accessible EPUB - Charles LaPierre - ebookcraft 2017
In the Trenches with Accessible EPUB - Charles LaPierre - ebookcraft 2017In the Trenches with Accessible EPUB - Charles LaPierre - ebookcraft 2017
In the Trenches with Accessible EPUB - Charles LaPierre - ebookcraft 2017
 
Building Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET CoreBuilding Beautiful REST APIs in ASP.NET Core
Building Beautiful REST APIs in ASP.NET Core
 
From Open Annotations to W3C Web Annotations (and the impact on IIIF Present...
From Open Annotations to W3C Web Annotations (and the impact on IIIF Present...From Open Annotations to W3C Web Annotations (and the impact on IIIF Present...
From Open Annotations to W3C Web Annotations (and the impact on IIIF Present...
 
3 Hacks to Improve WordPress Performance
3 Hacks to Improve WordPress Performance3 Hacks to Improve WordPress Performance
3 Hacks to Improve WordPress Performance
 
Hacking the Google Snippet - Digpen 7 workshop
Hacking the Google Snippet - Digpen 7 workshopHacking the Google Snippet - Digpen 7 workshop
Hacking the Google Snippet - Digpen 7 workshop
 
Parsing strange v4
Parsing strange v4Parsing strange v4
Parsing strange v4
 
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
The Ebook Developer's Toolbox - ebookcraft 2016 - Sanders Kleinfeld
 
Php reports sumit
Php reports sumitPhp reports sumit
Php reports sumit
 
Harnessing Free Content with Web Service APIs
Harnessing Free Content with Web Service APIsHarnessing Free Content with Web Service APIs
Harnessing Free Content with Web Service APIs
 
JSON API: Não reinvente a roda
JSON API: Não reinvente a rodaJSON API: Não reinvente a roda
JSON API: Não reinvente a roda
 
Why Django
Why DjangoWhy Django
Why Django
 

Viewers also liked (7)

OSS活動の活発さと評価の関係について
OSS活動の活発さと評価の関係についてOSS活動の活発さと評価の関係について
OSS活動の活発さと評価の関係について
 
power-assert in JavaScript
power-assert in JavaScriptpower-assert in JavaScript
power-assert in JavaScript
 
私にとってのテスト
私にとってのテスト私にとってのテスト
私にとってのテスト
 
ペアプログラミング ホントのところ
ペアプログラミング ホントのところペアプログラミング ホントのところ
ペアプログラミング ホントのところ
 
TDD のこころ @ OSH2014
TDD のこころ @ OSH2014TDD のこころ @ OSH2014
TDD のこころ @ OSH2014
 
RESTful Web アプリの設計レビューの話
RESTful Web アプリの設計レビューの話RESTful Web アプリの設計レビューの話
RESTful Web アプリの設計レビューの話
 
組織にテストを書く文化を根付かせる戦略と戦術
組織にテストを書く文化を根付かせる戦略と戦術組織にテストを書く文化を根付かせる戦略と戦術
組織にテストを書く文化を根付かせる戦略と戦術
 

Similar to Reviewing RESTful Web Apps

Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
Alvaro Graves
 
DSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/ExportDSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/Export
DuraSpace
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
Erik Hatcher
 

Similar to Reviewing RESTful Web Apps (20)

Crossref LIVE UK Online
Crossref LIVE UK OnlineCrossref LIVE UK Online
Crossref LIVE UK Online
 
Why do they call it Linked Data when they want to say...?
Why do they call it Linked Data when they want to say...?Why do they call it Linked Data when they want to say...?
Why do they call it Linked Data when they want to say...?
 
Crossref LIVE US Online
Crossref LIVE US OnlineCrossref LIVE US Online
Crossref LIVE US Online
 
Open Source Search Tools for www2010 conferencesourcesearchtoolswww20100426dA...
Open Source Search Tools for www2010 conferencesourcesearchtoolswww20100426dA...Open Source Search Tools for www2010 conferencesourcesearchtoolswww20100426dA...
Open Source Search Tools for www2010 conferencesourcesearchtoolswww20100426dA...
 
Crossref Content Registration - LIVE Mumbai
Crossref Content Registration - LIVE MumbaiCrossref Content Registration - LIVE Mumbai
Crossref Content Registration - LIVE Mumbai
 
Essentials for the SharePoint Power User - SPTechCon San Francisco 2016
Essentials for the SharePoint Power User - SPTechCon San Francisco 2016Essentials for the SharePoint Power User - SPTechCon San Francisco 2016
Essentials for the SharePoint Power User - SPTechCon San Francisco 2016
 
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
Essentials for the SharePoint Power User - SharePoint Engage Raleigh 2017
 
Content Registration at Crossref - LIVE Kuala Lumpur
Content Registration at Crossref - LIVE Kuala LumpurContent Registration at Crossref - LIVE Kuala Lumpur
Content Registration at Crossref - LIVE Kuala Lumpur
 
Content Registration - Crossref LIVE Hannover
Content Registration - Crossref LIVE HannoverContent Registration - Crossref LIVE Hannover
Content Registration - Crossref LIVE Hannover
 
HDP Next: Governance
HDP Next: GovernanceHDP Next: Governance
HDP Next: Governance
 
Metadata, Open Access and More: Crossref presentation
Metadata, Open Access and More: Crossref presentationMetadata, Open Access and More: Crossref presentation
Metadata, Open Access and More: Crossref presentation
 
How to build a data dictionary
How to build a data dictionaryHow to build a data dictionary
How to build a data dictionary
 
Creating web applications with LODSPeaKr
Creating web applications with LODSPeaKrCreating web applications with LODSPeaKr
Creating web applications with LODSPeaKr
 
APA ITU DOI?
APA ITU DOI?APA ITU DOI?
APA ITU DOI?
 
Working with Crossref and registering content
Working with Crossref and registering contentWorking with Crossref and registering content
Working with Crossref and registering content
 
Pragmatic REST APIs
Pragmatic REST APIsPragmatic REST APIs
Pragmatic REST APIs
 
Crossref LIVE Indonesia: Content Registration at Crossref, CRLIVE-ID 14 July ...
Crossref LIVE Indonesia: Content Registration at Crossref, CRLIVE-ID 14 July ...Crossref LIVE Indonesia: Content Registration at Crossref, CRLIVE-ID 14 July ...
Crossref LIVE Indonesia: Content Registration at Crossref, CRLIVE-ID 14 July ...
 
DSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/ExportDSpace 4.2 Transmission: Import/Export
DSpace 4.2 Transmission: Import/Export
 
OpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML ResourcesOpenTravel Advisory Forum 2012 REST XML Resources
OpenTravel Advisory Forum 2012 REST XML Resources
 
Solr Recipes Workshop
Solr Recipes WorkshopSolr Recipes Workshop
Solr Recipes Workshop
 

More from Takuto Wada

More from Takuto Wada (20)

unassert - encourage reliable programming by writing assertions in production
unassert - encourage reliable programming by writing assertions in productionunassert - encourage reliable programming by writing assertions in production
unassert - encourage reliable programming by writing assertions in production
 
OSS についてあれこれ
OSS についてあれこれOSS についてあれこれ
OSS についてあれこれ
 
SQLアンチパターン 幻の第26章「とりあえず削除フラグ」
SQLアンチパターン 幻の第26章「とりあえず削除フラグ」SQLアンチパターン 幻の第26章「とりあえず削除フラグ」
SQLアンチパターン 幻の第26章「とりあえず削除フラグ」
 
power-assert, mechanism and philosophy
power-assert, mechanism and philosophypower-assert, mechanism and philosophy
power-assert, mechanism and philosophy
 
アジャイルサムライの次に読む技術書
アジャイルサムライの次に読む技術書アジャイルサムライの次に読む技術書
アジャイルサムライの次に読む技術書
 
Test Yourself - テストを書くと何がどう変わるか
Test Yourself - テストを書くと何がどう変わるかTest Yourself - テストを書くと何がどう変わるか
Test Yourself - テストを書くと何がどう変わるか
 
テスト用ライブラリ power-assert
テスト用ライブラリ power-assertテスト用ライブラリ power-assert
テスト用ライブラリ power-assert
 
テストを書く文化を育てる戦略と戦術
テストを書く文化を育てる戦略と戦術テストを書く文化を育てる戦略と戦術
テストを書く文化を育てる戦略と戦術
 
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
SQLアンチパターン - 開発者を待ち受ける25の落とし穴 (拡大版)
 
SQLアンチパターン - 開発者を待ち受ける25の落とし穴
SQLアンチパターン - 開発者を待ち受ける25の落とし穴SQLアンチパターン - 開発者を待ち受ける25の落とし穴
SQLアンチパターン - 開発者を待ち受ける25の落とし穴
 
愛せないコードを書くには人生はあまりにも短い
愛せないコードを書くには人生はあまりにも短い愛せないコードを書くには人生はあまりにも短い
愛せないコードを書くには人生はあまりにも短い
 
例外設計における大罪
例外設計における大罪例外設計における大罪
例外設計における大罪
 
TDDBC お題
TDDBC お題TDDBC お題
TDDBC お題
 
DevLOVE DDDBC
DevLOVE DDDBCDevLOVE DDDBC
DevLOVE DDDBC
 
TDDBC Fukuoka Day1
TDDBC Fukuoka Day1TDDBC Fukuoka Day1
TDDBC Fukuoka Day1
 
js テスト放浪記
js テスト放浪記js テスト放浪記
js テスト放浪記
 
xUTP Chapter19 (2). Testcase Class
xUTP Chapter19 (2). Testcase ClassxUTP Chapter19 (2). Testcase Class
xUTP Chapter19 (2). Testcase Class
 
xUTP Chapter26. Dependency Injection
xUTP Chapter26. Dependency InjectionxUTP Chapter26. Dependency Injection
xUTP Chapter26. Dependency Injection
 
xUTP Chapter27 Generated Value
xUTP Chapter27 Generated ValuexUTP Chapter27 Generated Value
xUTP Chapter27 Generated Value
 
The only one big thing every programmer should know
The only one big thing every programmer should knowThe only one big thing every programmer should know
The only one big thing every programmer should know
 

Recently uploaded

Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 

Reviewing RESTful Web Apps

  • 1. Reviewing RESTful Web Apps Takuto Wada (a.k.a id:t-wada or @t_wada) Apr 12, 2014 @ RESTful Meetup
  • 3. tl;dr: REST is infection (Use it, love it, but think carefully.)
  • 4. •WEB+DB PRESS vol.32 •Discussion around Hatena-Bookmark •RubyKaigi 2006 Keynote by DHH •WEB+DB PRESS vol.38 •RESTful Web Service •RESTful Web APIs REST and me (input)
  • 5. •Java implementations (S2REST) •WEB+DB PRESS vol.42 Experiencing REST world with Restlet • Practical REST talk series by gihyo • #restwebtech book talk session REST and me (output)
  • 6. •Large Rails Project •+1000 routes •Tools for reviewing •White board •Chat (IRC, Skype, ...) •Wiki •diff Target Project
  • 7. 1. Figure out the data set 2. Split the data set into resources For each kind of resource: 3. Name the resources with URIs 4. Expose a subset of the uniform interface (GET/POST/PUT/DELETE) 5. Design the representation(s) accepted from the client 6. Design the representation(s) served to the client 7. Integrate this resource into existing resources, using hypermedia links and forms (Connectedness matters) 8. Consider the typical course of events: what s supposed to happen? 9. Consider error conditions: what might go wrong? Turning Requirements into Resources
  • 8. •URL Design (verb, structure, query params) •fighting with the gravity of CRUD •HTTP method •HTTP status code •Representation •MECE of information •Connectedness Review point
  • 9. Bad GET http://example.com/blog/getEntries Good GET http://example.com/blog/entries Bad POST http://example.com/blog/entries/add Good POST http://example.com/blog/entries Bad POST http://example.com/blog/entries/30/delete Good DELETE http://example.com/blog/entries/30 Do not include verbs in URL
  • 10. •/add, /delete, /update => Bad •/edit => it depends (convention matters) •Trying to use nouns •/confirm -> /confirmation •When the form of noun and verb are the same => it depends Do not include verbs in URL
  • 11. • Tumblr s Bizarre URL => Too Bad • http://www.tumblr.com/show/everything/by/me • Reads like spoken language doesn t matter • example.com/files/copy/:src/:dest => Bad • destination is not subordinated to source • Are they natural subordinates/subsets ? Is your URL natural?
  • 12. • URL Design is about searching for good names • standard names (microformats, W3C, ...) • dictionary, thesaurus, ... • Find the third resource , the resource representing relationship between resources. • subscription, participation, ... • Finally, ing s. belonging, tagging, ... Searching for names
  • 13. • What is it? => Meaning • How do I get it? => Will • Meaning shouldn t change even if query parameters are removed. • URL fragments should be composed of meaningful names. Meaning and Will in URL http://example.com/blog/entries?page=3&lang=ja Meaning of the Resource Will of client
  • 14. • Resources are not only Database Records. • Transactions • Calculation Results • Search Results Resources ≠ Database Records
  • 15. •Simple and automatic mapping looks nice •GET/POST/PUT/DELETE •SELECT/INSERT/UPDATE/DELETE •It s a trap! The Gravity of CRUD
  • 16. •Why trap? •Importance of models/tables varies. •Core Domain Models tend to have many more meanings and representations. •In contrast, some tables are just dependent tables. So they don t have their own representations. The Gravity of CRUD
  • 17. •Don t just map 3NF tables to resources •Some of them are too fine-grained •N+1 Problem appears! •Routes and Controllers should: •Fill the gap of granularity and viewpoint between Resources and Tables. •Map them if and only if it is meaningful. The Gravity of CRUD
  • 18. •What do you want to do to the Resource? •get it => GET •create new one => POST •modify it => UPDATE / PATCH •delete it => DELETE HTTP Methods
  • 19. •Contents is the king and so HTTP GET is the king. •To make Resources: •new Resource with new URL => POST •URL is known/given => PUT •If in doubt, use POST HTTP Methods
  • 20. •Status codes regularly used •200, 201, 204 •301, 303, 307, (304) •400, 404, 409, (401, 403, 422 (rails)) •500 •Client is wrong => 4xx •Server is wrong => 5xx HTTP Status Code
  • 21. •Mapping Errors to 4xx or 5xx •Models just raise Errors •Rails maps them •Want to hide resources => use 404 HTTP Status Code
  • 22. •Should contain URL or URL creator(forms) •No dead-ends •If you want to construct GET query parameters •use forms •forms are not only for POST requests Representation
  • 23. •Content Negotiation •use Accept, Accept-Language •Better to include representation formats in URL (fragments, extensions) •more better to include languages (ja,en,...) in URL Representation
  • 24. •Don t concat strings to create URL on the client side! •Client shouldn t know how to construct URLs •use URI-Templates •http://tools.ietf.org/html/rfc6570 Representation
  • 25. •Client can only change its application status by following links (or submitting forms) in representations served by servers For the Connectedess
  • 26. •Services should not enforce clients to construct URL •Services should not expect clients to construct URL •Services should serve representations with links(forms) for next application state transitions For the Connectedess
  • 28. tl;dr: REST is infection (Use it, love it, but think carefully.)