symfony camp 2013 ua resting with symfony2

22
Lukas Kahwe Smith | Liip AG [email protected] | @lsmith RESTing with Symfony2 Sunday, October 27, 13

Upload: lukas-smith

Post on 27-Jan-2015

141 views

Category:

Technology


4 download

DESCRIPTION

Introduction to REST (RMM, media types and content negotiation) with a short list of Symfony2 bundles. The actual meat of the talk is in the referenced demo application.

TRANSCRIPT

Page 1: Symfony Camp 2013 UA RESTing with Symfony2

Lukas Kahwe Smith | Liip [email protected] | @lsmith

RESTing with Symfony2

Sunday, October 27, 13

Page 2: Symfony Camp 2013 UA RESTing with Symfony2

Introduction to REpresentational State

Transfer

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 3: Symfony Camp 2013 UA RESTing with Symfony2

REST Maturity Model

RESTing

http://martinfowler.com/articles/richardsonMaturityModel.html

Lukas Kahwe SmithSunday, October 27, 13

Page 4: Symfony Camp 2013 UA RESTing with Symfony2

Level 0: The Swamp of POX•HTTP as a tunneling mechanism•“Procedural” communication (RPC)•Single endpoint (per operation)

Lukas Kahwe Smith

RESTing

Sunday, October 27, 13

Page 5: Symfony Camp 2013 UA RESTing with Symfony2

Level 1: Resources•Individual resources, i.e. URIs•“Object orientated” communication

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 6: Symfony Camp 2013 UA RESTing with Symfony2

Level 2: HTTP Verbs•Client uses specific HTTP method•Server uses HTTP status codes

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 7: Symfony Camp 2013 UA RESTing with Symfony2

Level 2: HTTP Methods

RESTing

Lukas Kahwe Smith

Method Safe? (★) Idempotent? (✦)

GET Yes YesHEAD Yes YesPOST No NoPUT No Yes

DELETE No Yes.. No No

(★) cacheable (✦) result independent on # of executions

Sunday, October 27, 13

Page 8: Symfony Camp 2013 UA RESTing with Symfony2

RESTing

Lukas Kahwe Smith

Code range Description Example

1xx Information 100 - Continue2xx Successful 201 - Created

3xx Redirection 301 - Moved Permanently

4xx Client Error 404 - Not Found

5xx Server Error 501 - Not Implemented

Level 2: HTTP status codes

Sunday, October 27, 13

Page 9: Symfony Camp 2013 UA RESTing with Symfony2

Level 3: Hypermedia Control•Service discovery via link relations•ATOM, HAL, JSON-LD, IANA Link Rel

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 10: Symfony Camp 2013 UA RESTing with Symfony2

RESTing

Hypertext As The Engine Of Application

State

Sunday, October 27, 13

Page 11: Symfony Camp 2013 UA RESTing with Symfony2

H A T E O A S

RESTing

Sunday, October 27, 13

Page 12: Symfony Camp 2013 UA RESTing with Symfony2

RMM vs REST vs real life

•RMM only covers a subset of REST•RMM Level 2 is what most developer think is sufficient for REST•RMM Level 3 is a REST precondition•RMM Level 3 makes URI formatting matter less

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 13: Symfony Camp 2013 UA RESTing with Symfony2

RMM vs REST vs real life

•REST is protocol independent•Few clients are prepared to leverage HATEOAS enabled REST APIs•Browsers are bad REST clients

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 14: Symfony Camp 2013 UA RESTing with Symfony2

URIs

•Identifies a resource•Independent of a specific format•URI “file extensions” != RESTful

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 15: Symfony Camp 2013 UA RESTing with Symfony2

Media Types•Identifies a representation format•Custom types «application/vnd.»

RESTing

Lukas Kahwe Smith

Header Description

Content-Type HTTP message format

Accept HTTP response format preference

Accept-Encoding, Accept-Language, ..

HTTP response preference

Sunday, October 27, 13

Page 16: Symfony Camp 2013 UA RESTing with Symfony2

Content Type Negotiation

•Finding appropriate response format•No standardized algorithm available•Apache mod_negotiation algorithm is well documented

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 17: Symfony Camp 2013 UA RESTing with Symfony2

Content Type NegotiationAccept: application/json,application/xml;q=0.9,text/html;q=0.8,*/*;q=0.7

RESTing

Lukas Kahwe Smith

Priority Description

q=0.9 application/json or application/xml

q=0.8 text/html

q=0.7 */* (anything)

Sunday, October 27, 13

Page 18: Symfony Camp 2013 UA RESTing with Symfony2

RESTing with Symfony2

RESTing

Lukas Kahwe SmithSunday, October 27, 13

Page 22: Symfony Camp 2013 UA RESTing with Symfony2

Further reading•http://martinfowler.com/articles/richardsonMaturityModel.html•http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-driven•http://www.slideshare.net/Wombert/designing-http-interfaces-and-restful-web-services-dpc2012-20120608•http://williamdurand.fr/2012/08/02/rest-apis-with-symfony2-the-right-way/•http://knpuniversity.com/blog/what-the-rest•http://knpuniversity.com/blog/rest-revisited

RESTing

Lukas Kahwe SmithSunday, October 27, 13