*
The moose likes Servlets and the fly likes What is an Idempotent Requests Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "What is an Idempotent Requests" Watch "What is an Idempotent Requests" New topic
Author

What is an Idempotent Requests

Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 257
What is Idempotent Request? Which all methods in Http are Idempotent and why. Please explain me the concepts. Thanks a lot.
[ July 24, 2007: Message edited by: David O'Meara ]
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8843
    
    7

Have a look at this.


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
you can think like if request is not modifying anything in your database(although server-side is more correct word) then it is idempotent.for example if you are firing select query.. definitely get is idempotent if you use it correctly..

post is non-idempotent as its purpose is to modify...
[ July 24, 2007: Message edited by: raj malhotra ]
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 257
fine GET method is idempotent and POST is not idempotent but what about the rest of the HTTP methods.... which are idempotent and which are not and why ???
sunny dhoni
Greenhorn

Joined: Jul 24, 2007
Posts: 9
GET - idempotent or safe (no side effects on server)
as it requests to return the content on the server and not modify it

POST - not impotent or unsafe (side effects on server)
as it might modify the contents on the server

HEAD - idempotent or safe (no side effects on server)
as it will just ask for header part and not the content in the response (response similar to GET except the body)

PUT - not impotent or unsafe (side effects on server)
ask the server to put or modify data on server at particular uri

DELETE - not impotent or unsafe (side effects on server)
delete the resource on server

OPTIONS - idempotent or safe (no side effects on server)
asks for options available on server like content-length

TRACE - idempotent or safe (no side effects on server)
ask to return traceback of the request

CONNECT - idempotent or safe (no side effects on server)
just ask to connect to the server with host and port args

for more info go to http://www.w3.org/Protocols/


You have the right to remain silent. Anything you say will be misquoted, then used against you.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
And it's not really about never making updates, but about making the same update every time. If a PUT sets shoe size to 8 every time you call it, it can still be idempotent. If it increments a counter every time, it isn't.

From W3C Protocols:

9.1.2 Idempotent Methods

Methods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.

However, it is possible that a sequence of several requests is non- idempotent, even if all of the methods executed in that sequence are idempotent. (A sequence is idempotent if a single execution of the entire sequence always yields a result that is not changed by a reexecution of all, or part, of that sequence.) For example, a sequence is non-idempotent if its result depends on a value that is later modified in the same sequence.

A sequence that never has side effects is idempotent, by definition (provided that no concurrent operations are being executed on the same set of resources).


All this tells how HTTP protocols "should" work. There's nothing but convention to prevent the code we add to an application server from breaking all the rules.

One time we care about this is when working with unreliable messaging. Maybe we send an update and never get a confirmation reply, so we send another copy of the same update. If it's idempotent, the second update will do no harm.
[ August 01, 2007: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Siddharth Bhargava
Ranch Hand

Joined: Feb 23, 2007
Posts: 257
Thanks everybody got the concept....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41182
    
  45
Originally posted by sunny dh:
PUT - not impotent or unsafe (side effects on server)
ask the server to put or modify data on server at particular uri

DELETE - not impotent or unsafe (side effects on server)
delete the resource on server

To expand on what Stan said, not only should PUT and DELETE be implemented in an idempotent manner, but being safe and being idempotent are not the same concept.
[ August 12, 2007: Message edited by: Ulf Dittmer ]

Ping & DNS - my free Android networking tools app
Hiral Jhaveri
Greenhorn

Joined: Nov 23, 2011
Posts: 5
Following was written by sunny :

PUT - not impotent or unsafe (side effects on server)
ask the server to put or modify data on server at particular uri


However, on Pg. 114 of "Head First Servlets and JSP", it is written that GET, PUT, HEAD are idempotent (it must have been misspelled as impotent) according to HTTP spec 1.1.

So I guess except POST (which passes data to the server "to be processed") every other HTTP method is idempotent. However, we can have an non-idempotent implementation of doGet() method in our Servlet but that does not mean that the HTTP GET method is non-idempotent.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60821
    
  65

A properly implemented PUT is idempotent. Setting a value to the same value will end up with the same result each time.

This is because idempotent does not mean "won't change the server", it means "results with the same result each time".


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is an Idempotent Requests
 
Similar Threads
Are webservices always about idempotent service APIs ?
idempotent methods
Regarding Idempotent Request
Idempotent???
SCWD-STUDY GROUP