Reputation: 2432
I am trying to decide which Http method should be used PUT or POST.
While looking at some posts on StackOverlflow I could see this post.
One of the answers in post says
PUT is idempotent, so if you PUT an object twice, it has no effect. This is a nice property, so I would use PUT when possible.
Can some one help me out here with an example. Lets say that I have a scenario where I am trying to create a student whose entry would be passed in Student table in a RDBMS.
So here if I try to PUT that entry again and again will there be no effect?
Upvotes: 7
Views: 4462
Reputation: 13682
In a PUT, you're setting all the values of the resource, so when the PUT is done, you know exactly what the state is of the resource. If you wait a week and call your PUT again, you still know exactly what the state is of the resource.
A POST, by contrast, is not idempotent - you only POST a subset of the values. So if you call POST today, wait a week, and make the same POST call again, you don't know what the state of the resource is - somebody might have changed a value you're not setting in the POST.
Idempotent means that no matter when or how often you make the call, the end state of the resource is exactly the same.
DELETE and GET are also idempotent.
Upvotes: 9