There are obvious counterparts for some of file systems\' basic operations (eg. ls
and rm
), but how would you implement not straightforwardly RESTf
[...the preferred way of implementing cp would include GETting the resource, DELETing it and PUTting it back again with a new name.]
One problem with the above approach is lack of atomicity and consistency. Since each of the operations (GET, DELETE and PUT) happen over HTTP (which is stateless inherently) the server cannot enforce atomicity. For any reason, the client may abort after any step before the last step and that would leave the server with an inconsistent state in terms of its data.
A possible approach:
HTTP/1.1 201 Created
Content-type:video/x-msvideo
Location:/videos/johns_videos/8765
Note: I prefer sending an ID back and working with resource IDs rather than something like
Location: /videos/johns_videos/copied-2-gigabyte-video.avi
Move operation is pretty similar except that the server may accept a destination resource. Example:
http://example.com//videos/johns_videos/8765/move?destination=[destination]
You can extend the above approach such that the server sends a Last-Modified tag to the client and client sends that along with its request. The server will perform the copy/move operations only when that value is still consistent. This will address concurrency issues with the resource being changed while your copy/move operations are still in progress.