This document discusses Representational State Transfer (REST) architectural styles and principles for designing web services. It describes how REST uses common HTTP verbs like GET, POST, PUT, and DELETE to transmit data in requests and standardized methods for returning successful responses and error messages. Key REST concepts covered include using URLs to identify resources and collections, supporting multiple representation formats like JSON or XML, and enabling caching for GET requests to improve performance.
1 of 20
Download to read offline
More Related Content
Rest
1. Your data needs to be
promiscuous
If theres any hope of it
hooking up with the iPhone
2. Your data needs to be
promiscuous
If theres any hope of it
hooking up with the iPhone
3. API
The I means Interface
Necessary to interact with any application
outside of a web site
Smart phone
Ajax
9. XML
James Clark:
My reaction to JSON is a combination of Yay and Sigh.
It's Yay, because for important use cases JSON is dramatically better
than XML. In particular, JSON shines as a programming language-
independent representation of typical programming language data
structures. This is an incredibly important use case and it would be hard
to overstate how appallingly bad XML is for this. The fundamental
problem is the mismatch between programming language data structures
and the XML element/attribute data model of elements.
10. Verbs
GET: Retrieve data
PUT: Replace data
POST: Add data
[PATCH]: Update data
DELETE: Remove data
12. Collections
GET: List items in a collection
PUT: Replace a collection with new items
Functions as a PATCH in the real world
POST: Add an item to this collection
New or existing item
DELETE: Remove all items in this collection
There be danger
13. Item
GET: Retrieve the representation of this item
PUT: Update the item with new values
Functions as PATCH in the real world
DELETE: Remove the item
14. Uniformity
Relative to a base URL
A description of resources often placed here
Collections are identi鍖ed by the type of object in
the collection
http://baseurl/resource/
Items are identi鍖ed by the type and ID of the
item
http://baseurl/resource/12
Collections can be related to a speci鍖c item
http://bareurl/parent/12/resource
15. Varied Representations
Requesting a return type may be done through
resource URL
http://baseurl/resource/12.json
http://baseurl/resource/12.html
Requesting a return type may be done through
Accept header
Accept: application/json
16. Responses
Use HTTP error codes where appropriate
Standardize a method of measuring success
Standardize a method of returning errors
Add an error 鍖ag
State the main error message
State the error type
Allow data to be conveyed along with the error
17. Blog
Uses many REST patterns
Collection of posts often at /blog/
Object type used for lookup
Items usually at /blog/id
Items can be added to a category collection of
posts
18. Caching
GET requests can be cached by browsers
Should never alter state
Several headers in the return enable it
No other verbs will be cached regardless of
headers