Download - Symfony Camp 2013 UA RESTing with Symfony2
Introduction to REpresentational State
Transfer
RESTing
Lukas Kahwe SmithSunday, October 27, 13
REST Maturity Model
RESTing
http://martinfowler.com/articles/richardsonMaturityModel.html
Lukas Kahwe SmithSunday, October 27, 13
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
Level 1: Resources•Individual resources, i.e. URIs•“Object orientated” communication
RESTing
Lukas Kahwe SmithSunday, October 27, 13
Level 2: HTTP Verbs•Client uses specific HTTP method•Server uses HTTP status codes
RESTing
Lukas Kahwe SmithSunday, October 27, 13
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
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
Level 3: Hypermedia Control•Service discovery via link relations•ATOM, HAL, JSON-LD, IANA Link Rel
RESTing
Lukas Kahwe SmithSunday, October 27, 13
RESTing
Hypertext As The Engine Of Application
State
Sunday, October 27, 13
H A T E O A S
RESTing
Sunday, October 27, 13
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
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
URIs
•Identifies a resource•Independent of a specific format•URI “file extensions” != RESTful
RESTing
Lukas Kahwe SmithSunday, October 27, 13
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
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
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
RESTing with Symfony2
RESTing
Lukas Kahwe SmithSunday, October 27, 13
Bundles for a REST Server
•FOSRestBundle•JMSSerializerBundle•NelmioApiDocBundle•BazingaHateoasBundle ( FSCHateoasBundle )
•TemplatedUriBundle•LiipCacheControlBundle•FOSOAuthServerBundle
RESTing
Lukas Kahwe SmithSunday, October 27, 13
Bundles for a REST Client
•FOSRestBundle•JMSSerializerBundle•HWIOAuthBundle•MisdGuzzleBundle
RESTing
Lukas Kahwe SmithSunday, October 27, 13
Demo Time!
https://github.com/lsmith77/symfony-rest-edition/tree/2.3
RESTing
Lukas Kahwe SmithSunday, October 27, 13
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