Idempotent ability we will get same end result with a couple of identical request.No count how many times the method has been called. It should not be counted if the approach has been referred to as only once, or ten instances over.. The result should always be the same.In REST API the following HTTP methods are idempotent:
GET, PUT, DELETE, HEAD, OPTIONS, and TRACE methods
and Only POST method is not idempotent.
1. Why POST method is not Idempotent?
POST is used to create a new resource on the server. So when we invoke the identical request N times, we will have N new resources on the server. Duplication is allowed here. So POST is not idempotent.
2. Why PUT method is Idempotent?
PUT is used to update the resource state. If you invoke a PUT method N times, the very first request will replace the resource; the other N-1 requests will simply overwrite the identical useful resource state again and again.
PUT must exchange the existing aid with the new one. This ability we cannot do partial updates. So, if we choose to replace a single area of the resource, we have to send a PUT request containing the whole resource. Hence, PUT is idempotent.
3. Why PATCH method is Idempotent?
PATCH is used for partial modifications to a resource.If the client sends data with an identifier, then it will check whether or not that identifier exists. If the identifier exists, we will replace the replace with the data, else it will throw an exception. Patch request says that we would only send the records that we want to modify without enhancing or effecting different parts of the data. PATCH does partial update.
Ex: if we need to update only the last name, you can pass only the last name.
4. Difference between PUT and PATCH method
PUT is an Idempotent:
1. PUT should replace the present useful resource with the new one.PATCH is Idempotent:
2. In PUT method, we are now not throwing an exception if an identifier is not located
1. While PUT is used to replace an existing resource, PATCH is used to apply partial modifications to a resource.5. Why GET method is Idempotent?
2. In PATCH method, we are throwing an exception if the identifier is not found.
GET is the simplest kind of HTTP request method; the one that browsers use each time you click a link or kind a URL into the address bar. It instructs the server to transmit the information identified by means of the URL to the client. Data need to never be modified on the server side as a result of a GET request. Means, a GET request is read-only
6. DELETE method is Idempotent
DELETE method is pretty easy to understand. It is used to delete a resource identified by a URI.On successful deletion, return HTTP status 200 (OK).
No comments:
Post a Comment