I'm building a server that allows clients to store objects.
(我正在构建一个允许客户端存储对象的服务器。)
Those objects are fully constructed at client side, complete with object IDs that are permanent for the whole lifetime of the object. (这些对象在客户端完全构造,完整的对象ID对于对象的整个生命周期是永久的。)
I have defined the API so that clients can create or modify objects using PUT:
(我已经定义了API,以便客户端可以使用PUT创建或修改对象:)
PUT /objects/{id} HTTP/1.1
...
{json representation of the object}
The {id} is the object ID, so it is part of the Request-URI.
({id}是对象ID,因此它是Request-URI的一部分。)
Now, I'm also considering allowing clients to create the object using POST:
(现在,我也在考虑允许客户端使用POST创建对象:)
POST /objects/ HTTP/1.1
...
{json representation of the object, including ID}
Since POST is meant as "append" operation, I'm not sure what to do in case the object is already there.
(由于POST意味着“追加”操作,我不知道如果对象已经存在该怎么办。)
Should I treat the request as modification request or should I return some error code (which)? (我应该将请求视为修改请求还是应该返回一些错误代码(哪个)?)
ask by vmj translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…