Consider the following PUT requests that build a CouchDB Database and add a document
curl -X PUT http://localhost:5984/mydb
Response: {“ok”:true}
curl -X PUT http://localhost:5984/mydb/mydoc -d '{"name":"John", "email":"john@example.com"}'
Response: {“ok”:true,”id”:”mydoc”,”rev”:”1-8c497db1c5b38cb65981a2c83b349d83″}
Ok, we’ve got a document. Now I want to delete this document. I try:
curl -X DELETE http://localhost:5984/mydb/mydoc -d '{"_rev":"1-8c497db1c5b38cb65981a2c83b349d83}'
Response: {“error”:”conflict”,”reason”:”Document update conflict.”}
Hmm. I don’t see why that doesn’t work, so I try this:
curl -X DELETE http://localhost:5984/mydb/mydoc?rev=1-8c497db1c5b38cb65981a2c83b349d83
Response: {“ok”:true,”id”:”mydoc”,”rev”:”2-e8b8b0632384aae62338c57e1826ea81″}
That works…but why? What’s wrong with the first? Any help is appreciated.
DELETErequests sharesGETsemantics and message body is ignored, so you need to use query parameters to pass revision token with request.