Sunday 30 August 2015

Why POST method is non-idempotent and GET is idempotent ?




GET Method:-HTTP GET method is just for getting things from server.It is not supposed to change anything on server.So GET method is idempotent.It can be executed more than once without any side effects.
As you can see in below diagram,User request for a page and servlet sends back a response with a generated HTML page.You can call the same page again and again and server will return the response with no negative consequences that is called idempotent.





POST Method:-HTTP POST method is not idempotent i.e. the data submitted in the body of POST might be destined for transaction that can't be reversed.
As below diagram explains that when you submit your form ,POST method updates the data in database and servlet sends back an response.SO when you perform the submit action again,It will generate different response.





PUT,HEAD,DELETE methods are IDEMPOTENT just like GET method.

Enjoy Learning :)

1 comment: