File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes What is an Idempotent Requests Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Servlets
Reply 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: 218
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: 7796

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: 284
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: 218
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: 218
Thanks everybody got the concept....
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 32421
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 ]

Android appsImageJ pluginsJava web charts
 
 
subject: What is an Idempotent Requests
 
developer file tools