I've read HTTP documentation, but I can't understand what is idempotency. Can someone help?
I've read HTTP documentation, but I can't understand what is idempotency. Can someone help?
In my understanding, idempotency has nothing to do with the result (=Server Response), but with the server-state after one or multiple calls.
Let's say you want to delete a resource on the server by calling
DELETE /resource/123
The call may return with a HTTP-Response 200 OK and the deleted resource as payload in the first place. In a second call, the Response will be 204 NO_CONTENT as the resource has already been deleted by the first call.
After each request the server-state is the same, therefore idempotency is fulfilled. The HTTP/1.1 says nothing about the response
A request method is considered "idempotent" if the intended effect on the server of multiple identical requests with that method is the same as the effect for a single such request
TLDR
Idempotenc : GET, PUT : WHY ?
GET If fired recursively exact /resource/123 it will give same result
PUT If fired recursively exact /user/123 it will give same result
NON Idempotence :DELETE ,POST : WHY ?
DELETE If fired recursively exact /user/123 it will give different result second time(404 or NOT_FOUND)
POST If fired recursively exact /user/(id is assigned by server) it will give different result every-time
Confusions : DELETE is Idempotenc by http docs , but its behaviour is Non-idempotence
Conclusion :
Request is Idempotenc
if request gives same result
for exact same url fired recursly
else non Idempotenc
An idempotent HTTP method is an HTTP method that can be called many times without different outcomes. It would not matter if the method is called only once, or ten times over. The result should be the same. It essentially means that the result of a successfully performed request is independent of the number of times it is executed. For example, in arithmetic, adding zero to a number is idempotent operation.
POST is NOT idempotent. GET, PUT, DELETE, HEAD, OPTIONS and TRACE are idempotent.
1>POST -->Every time you call this Method It will give Different Result Why-->Consider a Scenario where you are creating new resources Each time you call this method it will resulting in creating new resources Giving you the different result each time and hence ,POST(in simple word "Insert") is non idempotent method.
2>Other will Give you the Same result