Symfony Camp 2013 UA RESTing with Symfony2

4,358 views

Published on

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.

Published in: Technology
0 Comments
11 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
4,358
On SlideShare
0
From Embeds
0
Number of Embeds
1,266
Actions
Shares
0
Downloads
46
Comments
0
Likes
11
Embeds 0
No embeds

No notes for slide

Symfony Camp 2013 UA RESTing with Symfony2

  1. 1. RESTing with Symfony2 Lukas Kahwe Smith | Liip AG smith@pooteeweet.org | @lsmith Sunday, October 27, 13
  2. 2. RESTing Introduction to REpresentational State Transfer Lukas Kahwe Smith Sunday, October 27, 13
  3. 3. RESTing REST Maturity Model http://martinfowler.com/articles/richardsonMaturityModel.html Lukas Kahwe Smith Sunday, October 27, 13
  4. 4. RESTing Level 0: The Swamp of POX •HTTP as a tunneling mechanism •“Procedural” communication (RPC) •Single endpoint (per operation) Lukas Kahwe Smith Sunday, October 27, 13
  5. 5. RESTing Level 1: Resources •Individual resources, i.e. URIs •“Object orientated” communication Lukas Kahwe Smith Sunday, October 27, 13
  6. 6. RESTing Level 2: HTTP Verbs •Client uses specific HTTP method •Server uses HTTP status codes Lukas Kahwe Smith Sunday, October 27, 13
  7. 7. RESTing Level 2: HTTP Methods Method GET HEAD POST PUT DELETE .. Safe? (★) Yes Yes No No No No Idempotent? (✦) Yes Yes No Yes Yes No (★) cacheable (✦) result independent on # of executions Lukas Kahwe Smith Sunday, October 27, 13
  8. 8. RESTing Level 2: HTTP status codes Code range Description 1xx Information 2xx Successful 3xx Redirection 4xx Client Error 5xx Server Error Example 100 - Continue 201 - Created 301 - Moved Permanently 404 - Not Found 501 - Not Implemented Lukas Kahwe Smith Sunday, October 27, 13
  9. 9. RESTing Level 3: Hypermedia Control •Service discovery via link relations •ATOM, HAL, JSON-LD, IANA Link Rel Lukas Kahwe Smith Sunday, October 27, 13
  10. 10. RESTing Hypertext As The Engine Of Application State Sunday, October 27, 13
  11. 11. RESTing HATEOAS Sunday, October 27, 13
  12. 12. RESTing 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 Lukas Kahwe Smith Sunday, October 27, 13
  13. 13. RESTing 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 Lukas Kahwe Smith Sunday, October 27, 13
  14. 14. RESTing URIs •Identifies a resource •Independent of a specific format •URI “file extensions” != RESTful Lukas Kahwe Smith Sunday, October 27, 13
  15. 15. RESTing Media Types •Identifies a representation format •Custom types «application/vnd.» Header Description Content-Type HTTP message format Accept Accept-Encoding, Accept-Language, .. HTTP response format preference HTTP response preference Lukas Kahwe Smith Sunday, October 27, 13
  16. 16. RESTing Content Type Negotiation •Finding appropriate response format •No standardized algorithm available •Apache mod_negotiation algorithm is well documented Lukas Kahwe Smith Sunday, October 27, 13
  17. 17. RESTing Content Type Negotiation Accept: application/json,application/ xml;q=0.9,text/html;q=0.8,*/*;q=0.7 Priority Description q=0.9 application/json or application/xml q=0.8 text/html q=0.7 */* (anything) Lukas Kahwe Smith Sunday, October 27, 13
  18. 18. RESTing RESTing with Symfony2 Lukas Kahwe Smith Sunday, October 27, 13
  19. 19. RESTing Bundles for a REST Server •FOSRestBundle •JMSSerializerBundle •NelmioApiDocBundle •BazingaHateoasBundle ( FSCHateoasBundle ) •TemplatedUriBundle •LiipCacheControlBundle •FOSOAuthServerBundle Lukas Kahwe Smith Sunday, October 27, 13
  20. 20. RESTing Bundles for a REST Client •FOSRestBundle •JMSSerializerBundle •HWIOAuthBundle •MisdGuzzleBundle Lukas Kahwe Smith Sunday, October 27, 13
  21. 21. RESTing Demo Time! https://github.com/lsmith77/ symfony-rest-edition/tree/2.3 Lukas Kahwe Smith Sunday, October 27, 13
  22. 22. RESTing Further reading •http://martinfowler.com/articles/ richardsonMaturityModel.html •http://roy.gbiv.com/untangled/2008/rest-apismust-be-hypertext-driven •http://www.slideshare.net/Wombert/ designing-http-interfaces-and-restful-webservices-dpc2012-20120608 •http://williamdurand.fr/2012/08/02/rest-apiswith-symfony2-the-right-way/ •http://knpuniversity.com/blog/what-the-rest •http://knpuniversity.com/blog/rest-revisited Lukas Kahwe Smith Sunday, October 27, 13

×