这一切都取决于,首先你应该更多地谈论URI、资源和表示,而不是关心对象。
POST 方法是为非幂等请求或具有副作用的请求而设计的,但它可以用于幂等请求。
将表单数据 POST 到 /some_collection/
normalize the natural key of your data (Eg. "lowercase" the Title field for a blog post)
calculate a suitable hash value (Eg. simplest case is your normalized field value)
lookup resource by hash value
if none then
generate a server identity, create resource
Respond => "201 Created", "Location": "/some_collection/<new_id>"
if found but no updates should be carried out due to app logic
Respond => 302 Found/Moved Temporarily or 303 See Other
(client will need to GET that resource which might include fields required for updates, like version_numbers)
if found but updates may occur
Respond => 307 Moved Temporarily, Location: /some_collection/<id>
(like a 302, but the client should use original http method and might do automatically)
一个合适的散列函数可能像一些连接字段一样简单,或者对于大字段或值,可以使用截断的 md5 函数。详情请参阅[散列函数] 2。
我假设你:
- 需要与哈希值不同的标识值
- 无法更改用于身份的数据字段