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.
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
6. RESTing
Level 2: HTTP Verbs
•Client uses specific HTTP method
•Server uses HTTP status codes
Lukas Kahwe Smith
Sunday, October 27, 13
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. 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. RESTing
Level 3: Hypermedia Control
•Service discovery via link relations
•ATOM, HAL, JSON-LD, IANA Link Rel
Lukas Kahwe Smith
Sunday, October 27, 13
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. 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
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. 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. 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
19. RESTing
Bundles for a REST Server
•FOSRestBundle
•JMSSerializerBundle
•NelmioApiDocBundle
•BazingaHateoasBundle ( FSCHateoasBundle )
•TemplatedUriBundle
•LiipCacheControlBundle
•FOSOAuthServerBundle
Lukas Kahwe Smith
Sunday, October 27, 13
20. RESTing
Bundles for a REST Client
•FOSRestBundle
•JMSSerializerBundle
•HWIOAuthBundle
•MisdGuzzleBundle
Lukas Kahwe Smith
Sunday, October 27, 13