Sunday, March 22, 2015

Rest WebService Theory

To understand Rest - Lets see first -

What is Webservice?
If you Refer Wiki Page -"A Web service is a method of communication between two electronic devices over a network"

Let's understand it with this analogy -

  • Suppose you have created an awesome functionally to retrieve employee details -(using getEmpDetails() ). You can use this function to run in your application easily.  
  • Now if your friend wants to use this functionality you would give him this function but will he be able to run it ??? - No
  • He has the function but he doesn't have the DB and various other Config connection because that resides local to your system. So what you can do, now??
  • Put everything on a network and everybody can use it's functionality. This is the simplest thought to write a WebService.

In Short, This is a way so that an API can be used by everyone over Network.

There are two ways to write a WebService
  1. SOAP - Simple Object Access Protocol
  2. Rest - REpresentational State Transfer
  • Rest is a preferred way over more heavyweight SOAP 
  • Rest is an Architectural style to communicate over HTTP Protocol(not necessarily though), over standartd HTTP methods -- get, post ,put,delete

RESTful API HTTP methods
ResourceGETPUTPOSTDELETE
Collection URI, such ashttp://example.com/resources/List the URIs and perhaps other details of the collection's members.Replace the entire collection with another collection.Create a new entry in the collection. The new entry's URI is assigned automatically and is usually returned by the operation.[9]Delete the entire collection.
Element URI, such ashttp://example.com/resources/item17Retrieve a representation of the addressed member of the collection, expressed in an appropriate Internet media type.Replace the addressed member of the collection, or if it doesn't exist,create it.Not generally used. Treat the addressed member as a collection in its own right and create a new entry in it.[9]Delete the addressed member of the collection.


No comments:

Post a Comment