Response XML data = REpresentational State Transfer
TheURLidentifies theresource
HTTP GET methodoperates on the resource
htmlpage is transferredto the browser
REpresentational State transfer
The page ( application state ) is stored on theclient(browser)
Click on the link (resource) in page ( hypermedia )
New state transfer occurs
4. REST architecture for the WebWeb platforms Addressable Resources Web Container Addressable Resources Web Container
5. REST Tenets
Resources ( nouns )
Identifiedby aURI , For example:
http://www.parts-depot.com/parts
Methods ( verbs )to manipulate the nouns
Small fixed set:
GET, PUT, POST, DELETE
Read, Update, Create, Delete
Representationof the Resource
data and statetransferred between client and server
XML, JSON ...
Useverbstoexchangeapplication state andrepresentation
6. HTTP Example Request GET /music/artists/beatles/recordingsHTTP/1.1 Host: media.example.com Accept: application/xml Response HTTP/1.1 200 OK Date: Tue, 08 May 2007 16:41:58 GMT Server: Apache/1.3.6 Content-Type: application/xml; charset=UTF-8 Method ResourceRepresentation State transfer
7. REST in Five Steps*
Give everything an ID
Use standard methods
Link things together
Multiple representations
Stateless communications
http://www.infoq.com/articles/rest-introduction
Uniform Interface
8. Give Every Thing an Idhttp://company.com/customers/123456 Resource Collection name Primary key http://company.com/customers/123456/orders/12 http://example.com/orders/2007/11 http://example.com/products?color=green URI is the id, Every resource has a URI
URIs identify :
items, collections of items, virtual and physical objects, or computation results.
9. REST in Five Steps*
Give everything an ID
Use standard methods
Link things together
Multiple representations
Stateless communications
http://www.infoq.com/articles/rest-introduction
Uniform Interface
10. Use StandardHTTP Methods: GET= Read
GET to retrieve information
Shouldnot modifyanything
Cacheable
Example
GET /store/customers/123456
11. Use StandardHTTP Methods: POST= Create
POST toadd newinformation
add the entity ,appendto the container resource
POST /store/customers
carol
Response
HTTP/1.1 201 Created
Location: http://store/customers/789
12. Use StandardHTTP Methods: PUT = Update
PUT toupdateinformation
Full entitycreate/replaceused when you know the id
Example
PUT /store/customers/123456
jane
13. Use StandardHTTP Methods: DELETE
Remove (logical) an entity
Example
DELETE /store/customers/123456
14. Use StandardMethods:
http://www.infoq.com/articles/rest-introduction
Order Customer Mgmt Example
15. Use StandardMethods:
/orders
GET - list all orders
POST - submit a new order
/orders/{order-id}
GET - get an order representation
PUT - update an order
DELETE - cancel an order
/orders/average-sale
GET - calculate average sale
/customers
GET - list all customers
POST - create a new customer
/customers/{cust-id}
GET - get a customer representation
DELETE- remove a customer
/customers/{cust-id}/orders
GET - get the orders of a customer
Order Customer Mgmt Example
http://www.infoq.com/articles/rest-introduction
16. Use StandardHTTP Methods
HTTP Get, Head
Shouldnot modifyanything
Cache-able
With Correct use ofLast-ModifiedandETag
Idempotency:
PUT, DELETE, GET, HEAD can berepeatedand theresults are the same
17. REST in Five Steps*
Give everything an ID
Use standard methods
Link things together
Multiple representations
Stateless communications * Inspired by Stefan Tilkov:http://www.innoq.com/blog/st/presentations/2008/2008-03-13-REST-Intro--QCon-London.pdf
18. Link Things Together
Representations contain links to other resources
Service provideslinks in responseto the Client
Enables client to move the application from onestateto thenextby following alink
Representationscontain links to otherresources:
19. Link Things Together
Representationscontainlinksto otherresources
Put a service in different states by following links and filling in forms
Hypermedia as the engine of application state
HTML, XML, JSON, N3 can all be Hypermedia
Client is in charge
Serviceofferspotentialstates
Service does not impose state transition order
20. REST in Five Steps*
Give everything an ID
Use standard methods
Link things together
Multiple representations
Stateless communications * Inspired by Stefan Tilkov:http://www.innoq.com/blog/st/presentations/2008/2008-03-13-REST-Intro--QCon-London.pdf
21. Multiple Representations
Offer data in a variety of formats, for different needs