Saturday, 20 December 2008

Implementing Copy using REST

I have a requirement to implement "copy" functionality for a resource.

Given a resource at /asset-set/1234 I need to create copy at /asset-set/4567.

The obvious way to do it is to GET the resource at /asset-set/1234 and PUT it to /asset-set/4567. The issue I have with this is that the size of the resource may be significant and to GET the resource to PUT it back to the same server seems a bit wasteful.

There is a WebDAV verb COPY that I could potentially use, but would rather keep within the confines of the 4 standard HTTP Methods.

Representations of a resource in REST do not need to completely describe a resource. e.g. in Atom we may have a binary representation of an asset and also an atom+xml representation.

If I use alternate representations for the PUT method I could PUT an application/resource-ref representation which contains a URI to the representation we wish to copy. The server would then GET that resource (which would be local) and create the new resource using that information.

I would be interested on anyone's opinions on this (Is it RESTful?) and also if there is an alternate way of doing this?

No comments: