I'm having a problem with , understanding of idempotent , AS i guess GET won't have side-effect's ,and POST have side-effect .
But it doesn't make much sense to me...... because both have side-effects. GET or POST.
Can Someone Help me OUT. (Please Explain that Idempotent Request)
this link may help you understand -
Ulf Dittmer wrote:It's the job of the developer to ensure that his/her code does not violate specifications. It's not like there's an HTTP police that jumps into action if there's a non-idempotent doGet method being written. But it's the developer's fault nonetheless for not knowing his stuff.
In Head First Servlet and JSp book they have given do-Get() method is non-idempotent and HTTP 1.1 GET method is idempotent. , how IS it ?? , than your saying what they have given is wrong ??
Madangopal Venkatesan wrote:Hence, POST posts side effects while GET does not!
Not correct. I can write code in the doGet() method of a servlet that deletes the entire database.
GET's should not have side effects, but just because something is a GET doesn't mean that it will not. As already pointed out multiple times, it's the responsibility of the programmer to follow the rules.
An idempotent action is one that if repeated, gets the same result, and results in the same state. There is no requirement that idempotent actions be GET, but they usually are.
In Bear's twisted example, a GET that deletes the whole database can in idempotent. The GET deletes the database, and returns a "database is gone" response/page/status. If you repeat it, it will still delete the database and return the same thing.
A more useful example happens with a "buy" button on a webstore. You want to press the "buy" button once, and get the item. Pressing it twice should *not* get you two of them. An idempotent action would have the "buy" function return "one item bought" and the state of the server has one item in the "bought/to be shipped" state. If you repeat it, it still should have only one item in the bought state.
In HF, what they tried explaining was while the specs say HTTP GET must be idempotent, in terms of side effects, it is whole and sole responsibility of programmer to make sure that doGet is idempotent as well. There is nothing that can stop you doing anything you want from doGet.
The HTTP specification specifies that POST should be the only method that is non-idempotent. So that means whenever you write a non-idempotent servlet... You should implement doPost().
Hope that explains it.
My understanding is that a GET should return the state of a resource and produce NO side effects. So - no delete of a database or any other modification of a resource on a GET.
POST, PUT and DELETE are provided to modify resources.
This wikipedia article is rather clear.