Wednesday, September 17, 2008

Rest Uniform Interface

Rest defines a uniform interface, but it doesn't say how. It says, we should define the interface that other HTTP service used in common and understand the same way.

The most 4 popular HTTP methods that we already know (GET, POST, PUT and DELETE) can be defined as a uniform interface to communicate with the resources.
Let take a look at GET. HTTP GET is the best name for read operation. Let say two web sites, A and B, if we use HTTP GET to get some resource from web site A then web site B will have the same interface of getting its resource through the same HTTP GET, meaning all services on every website should have a uniform interface in providing it services or resources.

The Four Commonly Used Methods
  1. POST: HTTP POST is commonly used to create a resource which is a subordinate to any existing parent resource. Some time POST is also being used to the information we posted to its own state rather then creating a new resource. POST neither safe or idempotent, when you making two identical requests to a factory resource, may result in creating two subordinate resources with the same information.
  2. GET: HTTP GET is commonly used to request some data. we should implement the service that GET is a safe and idempotent method, meaning to say every request with GET should not result in changing server state. The client machine can make 10 or 100 times request, he/she will still get the same resource. It a bad idea to implement a resource that will increment any time client sends a request with GET to access the resources.

No comments: