You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@couchdb.apache.org by "Brian Candler (JIRA)" <ji...@apache.org> on 2010/02/08 17:26:27 UTC

[jira] Created: (COUCHDB-642) Support rev in PUT URL

Support rev in PUT URL
----------------------

                 Key: COUCHDB-642
                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
             Project: CouchDB
          Issue Type: New Feature
          Components: HTTP Interface
         Environment: trunk 08 Feb 2010
            Reporter: Brian Candler
            Priority: Minor


A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)

$ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
{"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}

$ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
{"error":"conflict","reason":"Document update conflict."}

$ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
{"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}

Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.


-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Re: [jira] Commented: (COUCHDB-642) Support rev in PUT URL

Posted by Klaus Trainer <kl...@web.de>.
Yes, there's no body with DELETE requests. Nonetheless, as with PUT
requests, you can specify the current revision number in the If-Match
header. So, you don't really need ?rev= for DELETE requests.

- Klaus


On Wed, 2010-08-18 at 15:16 +0100, Robert Newson wrote:
> The reason it you need ?rev= for DELETE is that there's no request
> body for DELETE, unlike for PUT. So I don't see that adding ?rev= for
> PUT is about consistency. It looks like a neat enhancement, though,
> the issues with precedence notwithstanding.
> 
> B.
> 
> On Wed, Aug 18, 2010 at 2:50 PM, Klaus Trainer (JIRA) <ji...@apache.org> wrote:
> >
> >    [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12899848#action_12899848 ]
> >
> > Klaus Trainer commented on COUCHDB-642:
> > ---------------------------------------
> >
> > We need to consider that the ETag in the If-Match header doesn't override the _rev field in the body either. In fact, if they are not equal, status code 400 Bad Request is returned.
> >
> > I'm certainly not the one who can and wants to decide whether this behaviour should better be changed or not.
> >
> > The only opinion I have about the issue is that things should be consistent. That's the actual reason why I wrote the patch: if the rev query parameter works with DELETE requests, it should work with PUT requests as well.
> >
> > In that sense, your argument that the _id field in the document is overridden and hence the _rev field should be as well, sounds reasonable. Consequently, the ETag should also override the body's _rev field in that case.
> >
> > I can change the current behaviour, so that the rev query parameter and the ETag override the _rev field in the body. However, I won't do anything in that direction, as long as I haven't heard any opinion of some core developers.
> >
> >> Support rev in PUT URL
> >> ----------------------
> >>
> >>                 Key: COUCHDB-642
> >>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
> >>             Project: CouchDB
> >>          Issue Type: New Feature
> >>          Components: HTTP Interface
> >>         Environment: trunk 08 Feb 2010
> >>            Reporter: Brian Candler
> >>            Priority: Minor
> >>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
> >>
> >>
> >> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
> >> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> >> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
> >> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
> >> {"error":"conflict","reason":"Document update conflict."}
> >> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> >> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
> >> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.
> >
> > --
> > This message is automatically generated by JIRA.
> > -
> > You can reply to this email to add a comment to the issue online.
> >
> >



Re: [jira] Commented: (COUCHDB-642) Support rev in PUT URL

Posted by Robert Newson <ro...@gmail.com>.
The reason it you need ?rev= for DELETE is that there's no request
body for DELETE, unlike for PUT. So I don't see that adding ?rev= for
PUT is about consistency. It looks like a neat enhancement, though,
the issues with precedence notwithstanding.

B.

On Wed, Aug 18, 2010 at 2:50 PM, Klaus Trainer (JIRA) <ji...@apache.org> wrote:
>
>    [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12899848#action_12899848 ]
>
> Klaus Trainer commented on COUCHDB-642:
> ---------------------------------------
>
> We need to consider that the ETag in the If-Match header doesn't override the _rev field in the body either. In fact, if they are not equal, status code 400 Bad Request is returned.
>
> I'm certainly not the one who can and wants to decide whether this behaviour should better be changed or not.
>
> The only opinion I have about the issue is that things should be consistent. That's the actual reason why I wrote the patch: if the rev query parameter works with DELETE requests, it should work with PUT requests as well.
>
> In that sense, your argument that the _id field in the document is overridden and hence the _rev field should be as well, sounds reasonable. Consequently, the ETag should also override the body's _rev field in that case.
>
> I can change the current behaviour, so that the rev query parameter and the ETag override the _rev field in the body. However, I won't do anything in that direction, as long as I haven't heard any opinion of some core developers.
>
>> Support rev in PUT URL
>> ----------------------
>>
>>                 Key: COUCHDB-642
>>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
>>             Project: CouchDB
>>          Issue Type: New Feature
>>          Components: HTTP Interface
>>         Environment: trunk 08 Feb 2010
>>            Reporter: Brian Candler
>>            Priority: Minor
>>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
>>
>>
>> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
>> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
>> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
>> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
>> {"error":"conflict","reason":"Document update conflict."}
>> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
>> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
>> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.
>
> --
> This message is automatically generated by JIRA.
> -
> You can reply to this email to add a comment to the issue online.
>
>

[jira] Updated: (COUCHDB-642) Support rev in PUT URL

Posted by "Klaus Trainer (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Klaus Trainer updated COUCHDB-642:
----------------------------------

    Attachment: 0001-Allow-for-the-current-revision-number-to-be.patch

The attached patch allows for specifying the revision number in the rev query parameter in an HTTP PUT request.

It will return status code 400 Bad Request if there are different revision numbers in the request body and the rev query parameter and/or the If-Match header.

To summarize, now there are three possibilities where to specify the revision number:
- rev query parameter
- If-Match header
- request body.
The revision numbers must be equal if specified at more than one place.

> Support rev in PUT URL
> ----------------------
>
>                 Key: COUCHDB-642
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: HTTP Interface
>         Environment: trunk 08 Feb 2010
>            Reporter: Brian Candler
>            Priority: Minor
>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
>
>
> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
> {"error":"conflict","reason":"Document update conflict."}
> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (COUCHDB-642) Support rev in PUT URL

Posted by "Brian Candler (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12899777#action_12899777 ] 

Brian Candler commented on COUCHDB-642:
---------------------------------------

I'd prefer that the rev in the URL overrode any value in the document, because:

(1) This is what happens for _id. That is, I believe that any _id within the document is ignored in a PUT, in favour of the id in the URL.

(2) I think it's more "relaxed" if I can specify the _id and _rev in the URL, then I can forget about what's in the document. If I were forced to erase the value in the document, or make it equal to what's in the URL, then I'd just put it in the document in the first place.


> Support rev in PUT URL
> ----------------------
>
>                 Key: COUCHDB-642
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: HTTP Interface
>         Environment: trunk 08 Feb 2010
>            Reporter: Brian Candler
>            Priority: Minor
>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
>
>
> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
> {"error":"conflict","reason":"Document update conflict."}
> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (COUCHDB-642) Support rev in PUT URL

Posted by "Klaus Trainer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12899946#action_12899946 ] 

Klaus Trainer commented on COUCHDB-642:
---------------------------------------

A use case where being able to specify the revision number as query parameter makes quite a lot of sense is adding an attachment to an existing document, e.g.

curl -X PUT http://127.0.0.1:5984/db/doc/attachment?rev=29-6f2ae59d419ed641b59cad675dbaf36c --data-binary @/home/fooman/Videos/foovie.vob -H 'Content-Type: video/mpeg

> Support rev in PUT URL
> ----------------------
>
>                 Key: COUCHDB-642
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: HTTP Interface
>         Environment: trunk 08 Feb 2010
>            Reporter: Brian Candler
>            Priority: Minor
>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
>
>
> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
> {"error":"conflict","reason":"Document update conflict."}
> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (COUCHDB-642) Support rev in PUT URL

Posted by "Paul Joseph Davis (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Paul Joseph Davis updated COUCHDB-642:
--------------------------------------

    Skill Level: New Contributors Level (Easy)

> Support rev in PUT URL
> ----------------------
>
>                 Key: COUCHDB-642
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: HTTP Interface
>         Environment: trunk 08 Feb 2010
>            Reporter: Brian Candler
>            Priority: Minor
>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
>
>
> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
> {"error":"conflict","reason":"Document update conflict."}
> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (COUCHDB-642) Support rev in PUT URL

Posted by "Klaus Trainer (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/COUCHDB-642?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12899848#action_12899848 ] 

Klaus Trainer commented on COUCHDB-642:
---------------------------------------

We need to consider that the ETag in the If-Match header doesn't override the _rev field in the body either. In fact, if they are not equal, status code 400 Bad Request is returned.

I'm certainly not the one who can and wants to decide whether this behaviour should better be changed or not.

The only opinion I have about the issue is that things should be consistent. That's the actual reason why I wrote the patch: if the rev query parameter works with DELETE requests, it should work with PUT requests as well.

In that sense, your argument that the _id field in the document is overridden and hence the _rev field should be as well, sounds reasonable. Consequently, the ETag should also override the body's _rev field in that case.

I can change the current behaviour, so that the rev query parameter and the ETag override the _rev field in the body. However, I won't do anything in that direction, as long as I haven't heard any opinion of some core developers.

> Support rev in PUT URL
> ----------------------
>
>                 Key: COUCHDB-642
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-642
>             Project: CouchDB
>          Issue Type: New Feature
>          Components: HTTP Interface
>         Environment: trunk 08 Feb 2010
>            Reporter: Brian Candler
>            Priority: Minor
>         Attachments: 0001-Allow-for-the-current-revision-number-to-be.patch
>
>
> A DELETE request lets you append ?rev=xxxx to the URL. But this doesn't work with a PUT request; you have to put the _rev in the body instead (even though the _id is taken from the URL path)
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"1-967a00dff5e02add41819138abb3284d"}
> $ curl -X PUT -d "{}" http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo?rev=1-967a00dff5e02add41819138abb3284d
> {"error":"conflict","reason":"Document update conflict."}
> $ curl -X PUT -d '{"_rev":"1-967a00dff5e02add41819138abb3284d"}' http://brianadmin:brianadmin@127.0.0.1:5984/briantest/foo
> {"ok":true,"id":"foo","rev":"2-7051cbe5c8faecd085a3fa619e6e6337"}
> Allowing ?rev in the URL would make PUT and DELETE more consistent, and would allow you to replace an existing JSON doc with another one without having to merge the _rev into it first.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.