Wednesday 9 January 2013

Advantages for consuming RESTful services



1.     What is Rest

REST service is based on HTTP protocol. Each method invocation is a http get,post,delete or put request. Since it is HTTP protocol based so anything that can talk http can consume your service without much effort i.e. javascript, C#, Java, Whatever.
Also REST call results can be cached like normal http pages (by intermediate proxies or client machine) if you send the right caching parameters with the response.
However it is also more oriented towards 'resources' while normal WCF service is oriented towards RPC style communication.
Normal WCF supports callbacks and whole lot of other things that REST doesn't support but obviously it comes with cost of platform compatibility and complexity.

2.     What is Advantages of consuming RESTful services

  1. ·         REST is powerful, intuitive, and relatively easy to implement.
  2. ·         Light weight – not lot of extra xml markup as in SOAP.
  3. ·         Unlike SOAP it provides much simpler result that can be human readable.
  4. ·         It is very easy to build no extra toolkits are required.
  5. ·         Improve scalability of the application through caching and session state.
  6. ·         Custom URIs using URI templates
  7. ·         Consistency with design of the World Wide Web
  8. ·         Lightweight - not a lot of extra xml markup
  9. ·         Human Readable Results
  10. ·         Easy to build - no toolkits required
  11. ·         Each operation in a service is uniquely identified.
  12. ·         Each operation has their, own unique URI and can be accessed via this URL all across the web. 
  13. ·         Each URL is an object representation.
  14. ·         The Object can retreived using HTTP GET.
  15. ·         The Object can be deleted using a POST or PUT, use DELETE to modify the object
  16. ·         It is firewall friendly and it is fairly simple and straight forward.



3.     More About RESTful services

  1.  The Restful web services are nothing but a web programming model to expose WCF Service.
  2.  REST can have more impact on data transfer reduction in combination with JSON or other serialization techniques.
  3. REST stands for Representation State Transfer. Representation State Transfer term is invented by one of the original author of the HTTP protocol, Roy Fielding in his 2000 doctoral dissertation.  Visit the wiki  for more about REST.



4.     KEY CONCEPTS OF REST

  1. Resources: Resources are nothing but entities in a business domain for ex.  Items, Vendors, Customer etc…
  2. URIs: All resources are referenced using URIs (Universal Resource Identifiers)
  3. Representations: It consist of 2 things Data that reflects current or desired state, meta   data that provides description of data values. For ex. HTML, XML, JSON, Text files, zip, Images, Mpegs etc…


5.     Example


                [OperationContract(Name = " AddTwoNumber ")]
        [WebInvoke(UriTemplate = "/", Method = "POST")]
         int AddTwoNumber(int i, int j);

       

        [OperationContract(Name = " SubTwoNumber")]
        [WebGet(UriTemplate = "/")]
        int SubTwoNumber(int i, int j);


Happy Programming!!

Don’t forget to leave your feedback and comments below!

If you have any query mail me to Sujeet.bhujbal@gmail.com     


Regards

Sujeet Bhujbal
--------------------------------------------------------------------------------
-----------------------------------------------------------------------------------


No comments:

Post a Comment