aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Why put is not considered non-idempotent? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Why put is not considered non-idempotent?" Watch "Why put is not considered non-idempotent?" New topic
Author

Why put is not considered non-idempotent?

Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Hi,
I have a confusion, that we consider post non-idempotent. While we don't consider put non-idempotent. If allowed by the servers, put can change the
state of the server as well. So why put is not considered non-Idempotent?
Thanks,
Ben


Twitter:ben_pheonix
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

"Idempotent" doesn't actually mean that it can't change the state - that's a common misuse of the word. It means that if the operation is made multiple times it has the same effect as making it just once. So, for example, if you have a POST request that creates a new record, then applying it twice will create two records. So that isn't idempotent.

The word for an operation that has no side effects is "nullipotent".

Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Dear Mathew,

Doesn't put come under category of Post as well? If we repeat the operation of put twice, it can also create the same effect as post. Then why not put
considered non-idempotent.

Thanks,
Ben
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61433
    
  67

Ben Pheonix wrote:Doesn't put come under category of Post as well?

No. A PUT, executed with the same data, will have the exact same effect each time it is executed.

If you're "not looking" and a random number of PUTs occur, then how would you tell how many PUTs occurred while you had the blindfold on? You can't. Because the effect of executing 17 of the PUTs, or 17 million of them, has the exact same effect of executing one PUT.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4422
    
    8

Put should be idempotent. Of course, you can implement it to not be - you can implement GET to be not-idempotent if you want. But you won't be following the HTTP specification.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1696
    
  25

Hi Ben,

No PUT doesn't have side effects, it just creates a resource once or when PUT is used multiple times (of the same resource) it overrides the resource.

Just check the this part of the HTTP specs.

Regards,
Frits
Ben Pheonix
Ranch Hand

Joined: Dec 11, 2012
Posts: 46
    
    1

Dear Frits, mathew, bear,

Thank you so much for the help. I am clear on the concept now.

Thanks,
Ben
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why put is not considered non-idempotent?