Friday, July 29, 2016

HTTP Operations, Safe and Idempotent operations..

Method
Operation performed on server
Quality
GET
Read a resource.
Safe
PUT
Insert a new resource or update if the resource already exists.
Idempotent
POST
Insert a new resource. Also can be used to update an existing resource.
N/A
DELETE
Delete a resource .
Idempotent
OPTIONS
List the allowed operations on a resource.
Safe
HEAD
Return only the response headers and no response body.
Safe

A Safe operation is an operation that does not have any effect on the original value of the resource. For example, the mathematical operation "divide by 1" is a safe operation because no matter how many times you divide a number by 1, the original value will not change. 

An Idempotent operation is an operation that gives the same result no matter how many times you perform it. For example, the mathematical operation "multiply by zero" is idempotent because no matter how many times you multiply a number by zero, the result is always same. 

Similarly, a Safe HTTP method does not make any changes to the resource on the server. An Idempotent HTTP method has same effect no matter how many times it is performed. Classifying methods as Safe and Idempotent makes it easy to predict the results in the unreliable environment of the Web where the client may fire the same request again.

1 comment: