PUT vs POST - Confusion Abounds
In my research on REST this last week, I’ve seen several comments noting confusion on whether to use PUT or POST. After reading several references (Elliotte Rusty Harold, Sacrificial Rabbit, and Mark Baker) , I loosely paraphrase the rule as:
Use PUT when you know the ID of the resource you are creating or modifying and the operation is idempotent. Use POST otherwise.
In other words, don’t bother with CRUD as an analogy. Instead think:
GET –> View Representation of Resource
PUT –> Create/Modify client-identified Resource
POST –> Create/Modify server-identified Resource
DELETE –> Delete Resource
Updated on 11/4 to add the idempotent piece above.
This (and the SOAP/REST diagram you posted earlier) is great. I’ve built a REST web service strongly influenced by the Atom publishing protocol for our CMS product at work, but expressing the whys and hows of REST still gets confusing. I’m trying to distill all this wisdom for my talk at CodeCamp next weekend, REST and Its Discontents. I hope you’ll be able to make it.
http://www.twincitiescodecamp.com/TCCC/Sessions.aspx