Saturday, September 26, 2009

RESTful Web Services - Concept

Web has been in fast transformation since its inception and over the years, it has been piled up lots of overloading concepts that it has lost its original self.

Original Web Concept: URL was meant to identification of a server resource with which clients can communicate via a standard protocol like HTTP and exchange its representation.

But today server does lot more work including maintaining client state, caching, session management, security etc and all done by same resource. If you observe today's web app architecture, it is mostly working around shortcomings of original design.

Mr. Roy Fielding attempted to bring back the original web with his RESTful approach.  


REST Definition:
  • A Resource - Source of specific info
  • Identification of Resource - URL
  • Communication with Resource/component via standard interface - HTTP
  • Exchange the representation of these resources - Document, SOAP, JSON
Key goals of REST:
  • Scalability of component interactions;
  • Generality of interfaces;
  • Independent deployment of components;
  • Intermediary components to reduce latency, enforce security and encapsulate legacy systems
Six REST Characteristics: 
REST bring back original relationship between Client and Server. 

  • Client Server - Client and server are uniformly separated of each other concerns. Client does not bother about storage of data and Server does not bother about state of client or user interaction. This makes server very scalable.
  • Stateless - Client is responsible for all the user interaction and maintaining the state. Server does not need to remember client state between request of session. Request will be self fulfilling. This make server more scalable and reliable in case of partial failure of network or servers.
  • Cacheable -  Client is able to cache a responses but needs to ensure that response in explicit with consideration of state data. This further reduces the client-server interaction and improves scalability and performance.
  • Uniform Interface - Separation of concerns brings decoupling of these and allows both to evolve independently.
  • Layered System - Client are designed to be independent from direct connection with main server or intermediate server. This allows other feature load balancing, security and shared cache between middle server and client.
  • Code On Demand - Server can transfer some functionality from itself to client application just like Applet, AJAX,
RESTful Web Services:
A collection of resources designed on REST principles with web services.
  • Base URI - http://www.spsps.com/resources
  • MIME Type data support - JSON/XML/YAML
  • A set of supported operations - POST, GET, PUT or DELETE
RESTful Web Service HTTP methods:


Resource
GET
PUT
POST
DELETE
Collection URI. E.g. http://example.com/resources/
List the collection with their member's URIs. 
Replace the entire collection with another collection
Create a new entry in the collection where the ID is assigned automatically by the collection. Response carries ID back to Client.
Delete the entire collection
Member URI. E.g. http://example.com/resources/7HOU57Y
Retrieve a representation the addressed member of the collection expressed in an appropriate MIME type
Update the addressed member of the collection or Create it with the specified ID.
Treating the addressed member as a collection and creating a new subordinate of it.
Delete the addressed member of the collection.


References: 

0 comments:

Post a Comment