This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of The Little Book of Impediments (e-book only) and have Tom Perry on-line!
See this thread for details.
Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can anyone explain Idempotent requests?

 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi guys,

reading this book HFSJ, but i have not understood the explanation of Idempotent.

I have a form which uses GET request, i submit the form and in the servlet i use the form data to update a record in the database.
does that mean the record in database is not updated? if not such kind of update, than what exactly it means.

thanks

rafi
 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
GET is inherently supposed to be idempotent i.e. generally get requests can be made multiple times without making any effects. If you submit a form using GET request and update the database, then multiple requests might make an effect. So in that case your GET request won't be idempotent. We should try to avoid such situations where a GET (or other idempotent HTTP methods) make an effect when multiple requests are made using them...
 
Swagato Bhatta
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What I understand is basically this. In realitity there is no such thing as idempotent ! Because both get and post can be used to change values in the server side or cause side effects.

However, I feel the spec might state that we are supposed to use the GET such that it should not cause any sideeffect. Hence, we should supposedly use GET as idempotent and post as non-idempotent

I think the JAVA guys at SUN should alltogether stop this concept or create some other mechanism as GET can be used to cause sideffects!
 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
dude Get....Put.....Trace are idempotent....put and trace are safe too....GET is supposed to be idempotent....SUN recommends that GET should be used in such a way that nothing gets changed in the server.....because that is the underlygin concept of GET method.....you can change the data doesnt mean you should do it. its just a bad way of implementing it.....
 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swagato Bhatta wrote:I think the JAVA guys at SUN should alltogether stop this concept or create some other mechanism as GET can be used to cause sideffects!

This has nothing to do with Java. This is how GET method is defined in the HTTP specification. It is a general guideline to make GET requests idempotent, but no one can stop you from designing your application in such a way that GET requests are non-idempotent...
 
shivendra tripathi
Ranch Hand
Posts: 263
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Swagato Bhatta wrote:What I understand is basically this. In realitity there is no such thing as idempotent ! Because both get and post can be used to change values in the server side or cause side effects.

However, I feel the spec might state that we are supposed to use the GET such that it should not cause any sideeffect. Hence, we should supposedly use GET as idempotent and post as non-idempotent


Your understanding is correct!
 
Ankur Jain Kothari
Ranch Hand
Posts: 154
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
twist in the tale
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:GET is inherently supposed to be idempotent i.e. generally get requests can be made multiple times without making any effects. If you submit a form using GET request and update the database, then multiple requests might make an effect. So in that case your GET request won't be idempotent. We should try to avoid such situations where a GET (or other idempotent HTTP methods) make an effect when multiple requests are made using them...


you said :
generally get requests can be made multiple times without making any effects.

and
f you submit a form using GET request and update the database, then multiple requests might make an effect. So in that case your GET request won't be idempotent.

we should try to avoid situations


if you explain this texts of yours using a real example, in the sense that:

1. there is two form purchaseGET.html & purchasePOST.html, both of them accessing same servlet
2. the servlet is performing some update in the database
3. if this servlet is invoked multiple times from either of the two html files, which one will have side effects and which one won't ?
4. which of the two methods are recommended by HTTP Specification?


reading one reply i feel that oh this idempotent stuff are just theory or lets say an advise and doesn't exists in real life, but reading other one i get confused saying it will have side effects or we should avoid using them.

If anyone can post one perfect example with a proper explanation {showing that ok, if we invoke this servlet with GET we have these advantages/disadvantages, effects/side effects, recommended/not recommenned, good programming behavior or not}, that example can always be used as a sample to everyone who is confused with the topic.

Searching through the forum, i found few threads on this topic, where everyone says different things.

Thanks for your replies everyone,

Regards,

Rafi


 
Ankit Garg
Sheriff
Posts: 9579
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rafi Fareen wrote:1. there is two form purchaseGET.html & purchasePOST.html, both of them accessing same servlet
2. the servlet is performing some update in the database
3. if this servlet is invoked multiple times from either of the two html files, which one will have side effects and which one won't ?

Both will have side effects
Rafi Fareen wrote:4. which of the two methods are recommended by HTTP Specification?

For this case POST would be the recommended method to make a request to that servlet as it is making a side effect...
 
Rafi Fareen
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ankit Garg wrote:
Rafi Fareen wrote:1. there is two form purchaseGET.html & purchasePOST.html, both of them accessing same servlet
2. the servlet is performing some update in the database
3. if this servlet is invoked multiple times from either of the two html files, which one will have side effects and which one won't ?

Both will have side effects
Rafi Fareen wrote:4. which of the two methods are recommended by HTTP Specification?

For this case POST would be the recommended method to make a request to that servlet as it is making a side effect...


OK, Thanks alot.
 
Bunty Naagar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry to be off topic but when I first read this term in the HFSJ book- I thought they made it up( I am new to web stuff)
I found it even more hillarious on discovering that it actually existed!!
Just pronouncing it makes me giggle
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic