Thursday, May 21, 2015

REST Service

   REST
          ·          Introduced in 2000 by Roy Fielding at the University of California
           ·    stands for Representational  State Transfer
          ·         uses Current features of the  web in a simple and effective way
o   Uses http protocol
o   Uses HTTP protocol methods
o   Http protocol is stateless
o   URI locate any resource on the web
          ·         is an architectural style built on certain principles using the current web fundamentals



Architectural style:
         ·         Is a concept/theory, it’s up to the developer how he/she takes the concept and implements it.
         ·         Layered architecture is an architectural style somebody will takes it and implement  using web services, class or components
         ·         E.g. Three tier, service oriented  style,  rest is an architectural style
         ·         Can also be implemented outside the software world, can be used for Postal services.



Architectural Pattern  
         ·         is provides solution at subsystem level or at the module level
         ·         When we say it is an architectural pattern then we talks about component, subsystem or at module level.
         ·         MVC is an architectural level



Design Pattern:
         ·         Is the solution at code level
         ·         It talks about classes, methods and how the business logic flows.






Five basic fundamentals/principles of HTTP web which are leveraged to implement REST services
       
      
      1.       Resources: Everything is a resource like when we interact in internet it’s all about giving or taking data. A data can be in the format of web page, dynamic output, files, images, videos. So first think in REST is to start thinking everything as resources.



      2.       Unique Identifier: Every resource is identified by a unique identifier (URI).

For e.g.: If we want to display Customer with and order then the URI will be
                www.abc.com/DisplayCustomerData.jsp

For e.g.: If we want to display the details of Customer name Amit
                www.abc.com/Customer/Amit

For e.g.: If we want to display the details of Customer name Bhanu
                www.abc.com/Customer/Shiv


      
      3.       Simple/Uniform interfaces: Use simple and uniform interfaces by using HTTP methods (GET, PUT, POST, and DELETE) with the resource name.

o   When external clients are interacting then use simple interfaces so that it will be easy for the clients to understand.

o   For e.g. methods like :
§  AddCustomer: adding the customers
§  InsertOrders: inserting the orders
§  getOrders : for getting the order

Above method names are inconsistent and  difficult to remember.Use HTTP protocols/methods to make it uniform:
o   GET   -- getting the resource
o   POST  --  submitting the resource
o   Delete – deleting the resource
o   Put – create or update the resource



       4.       Representation: All communications are done via representation i.e. to and fro between client and server or in other words Request/Response between client and server.

E.g. Request send to the server by client in a form of following representation (in xml ):
                <Customer>
                                <Name> ABC</Name>
<Address> Mumbai </Address>
</Customer>


Similarly the response will be in some sort of representation, in xml for the above case. Similarly the representation can be in other formats like json etc.




      5.       Be stateless: Every request should be an independent request so that we can scale up using Load balancing




Independent Request means apart from the data we also send the state of the request so the server can carry forward.

No comments:

Post a Comment