RESTful 复制/移动操作? [英] RESTful copy/move operations?

查看:49
本文介绍了RESTful 复制/移动操作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设计一个类似于 RESTful 文件系统的服务,但复制/移动操作给我带来了一些麻烦.

I am trying to design a RESTful filesystem-like service, and copy/move operations are causing me some trouble.

首先,使用 PUT 到文件的最终 URL 来上传新文件:

First of all, uploading a new file is done using a PUT to the file's ultimate URL:

PUT /folders/42/contents/<name>

问题是,如果新文件已经以不同的 URL 驻留在系统上怎么办?

The question is, what if the new file already resides on the system under a different URL?

复制/移动想法 1:带有自定义标题的 PUT.

Copy/move Idea 1: PUTs with custom headers.

这类似于 S3 的副本.看起来与上传相同的 PUT,但带有自定义标头:

This is similar to S3's copy. A PUT that looks the same as the upload, but with a custom header:

PUT /folders/42/contents/<name>
X-custom-source: /files/5

这很好,因为在复制/移动时很容易更改文件名.但是,S3 不提供移动操作,可能是因为使用此方案的移动不会是幂等的.

This is nice because it's easy to change the file's name at copy/move time. However, S3 doesn't offer a move operation, perhaps because a move using this scheme won't be idempotent.

复制/移动创意 2:POST 到父文件夹.

Copy/move Idea 2: POST to parent folder.

这类似于 Google 文档副本.带有描述源文件的 XML 内容的目标文件夹的 POST:

This is similar to the Google Docs copy. A POST to the destination folder with XML content describing the source file:

POST /folders/42/contents
...
<source>/files/5</source>
<newName>foo</newName>

我也许可以 POST 到文件的新 URL 以更改其名称..?否则,我只能在 XML 内容中指定一个新名称,这会放大这个想法的 RPCness.与idea 1的上传操作也不一致.

I might be able to POST to the file's new URL to change its name..? Otherwise I'm stuck with specifying a new name in the XML content, which amplifies the RPCness of this idea. It's also not as consistent with the upload operation as idea 1.

最终我正在寻找易于使用和理解的东西,所以除了对上述的批评之外,当然欢迎新的想法!

Ultimately I'm looking for something that's easy to use and understand, so in addition to criticism of the above, new ideas are certainly welcome!

推荐答案

HTTP 规范说如果资源已经存在,那么你更新资源并返回 200.如果资源不存在,则创建它并返回 201.

The HTTP spec says if the resource already exists then you update the resource and return 200. If the resource doesn't exist then you create it and you return 201.


好吧,我看错了.与父文件夹方法相比,我更喜欢 POST.您还可以使用查询字符串参数引用源文件.例如


Ok, I misread. I prefer the POST to the parent folder approach. You could also refer to the source file using a query string parameter. e.g.

POST /destination/folder?sourceFile=/source/folder/filename.txt

这篇关于RESTful 复制/移动操作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆