tags:

views:

120

answers:

3

Quoting from the CouchDB documentation:

It is recommended that you avoid POST when possible, because proxies and other network intermediaries will occasionally resend POST requests, which can result in duplicate document creation.

To my understanding, this should not be happening on the protocol level (a confused user armed with a doubleclick is a completely different story). What is the best course of action, then?

Should we really try to avoid POST requests and replace them by PUT? I don't like that as they convey a different meaning.

Should we anticipate this and protect the requests by unique IDs where we want to avoid accidental duplication? I don't like that either: it complicates the code and prevents situations where multiple identical posts may be desired.

+2  A: 

Should we really try to avoid POST requests and replace them by PUT? I don't like that as they convey a different meaning.

For document creation (as mentioned in the doc you cite), that is exactly the correct meaning. For document modification, occasional resent requests are not a problem.

Michael Borgwardt
A: 

I must have been extremely lucky in my WebMaster days to never have seen duplicate POST requests.

TCP/IP sends numbered messages, I wouldn't know why any webserver wouldn't discard of the duplicates.

Is this duplicate POST thing really an issue?

deltreme
Only with **really** broken proxies, since it's used for financial transactions on normal websites.
Donal Fellows
A: 

We should avoid POST requests when the request is idempotent and does change server state (it should not change the server state each time it is performed, in document creation this means the document should only be created once).

POST is suitable when the request is non-idempotent. This means that everytime the request is sent there is a change in server state. For an update or delete this should not matter.

Of course, due to web browser support only GET and POST requests have really been adopted because POST does all that PUT does (it's just not designed for idempotent requests).

David Neale
I think you have it backwards: POST is good for idempotent changes (trying to delete something for a second time may yield an error, but will not corrupt data) and not good for non-idempotent ones (e.g. accidentally creating a document twice).
Michael Borgwardt
Are you sure? PUT is listed as idempotent and POST as non-idempotent. Delete is probably a bad example because that should really be done by the idempotent DELETE method.
David Neale