简体   繁体   English

REST-在PUT之后处理服务器端的修改(例如创建日期)

[英]REST - deal with modification from server side after PUT (such as the date of creation)

Since PUT is idempotent, how handle the situation which with the server add or change informations from the object send by the client ? 由于PUT是幂等的,如何处理服务器添加或更改客户端发送的对象中的信息的情况?

If all my resources have 'createdDate' and 'updatedDate' fields, should the client always use PATCH method (and never PUT) if I don't want the client to choose the value of these fields ? 如果我所有的资源都有'createdDate'和'updatedDate'字段,如果我不希望客户端选择这些字段的值,客户端是否应该始终使用PATCH方法(从不使用PUT)?

PUT replaces the resource pointed to by the URL. PUT 替换 URL指向的资源。
PATCH modifies the resource pointed to by the URL. PATCH 修改 URL指向的资源。

If you are modifying some subset of the properties of a resource, then PATCH is appropriate. 如果要修改资源属性的某些子集,则PATCH是适当的。

Just because PUT replaces an object in full doesn't mean you have to expose all fields for update. 仅仅因为PUT完全替换了对象并不意味着您必须公开所有字段以进行更新。 If you want create and updated dates done only on the backend, then do not expose them in either your PUT or PATCH methods. 如果要仅在后端完成创建和更新日期,则不要在您的PUT或PATCH方法中公开它们。

Your RESTful API does not have to be exactly the same as your persistence/database methods. RESTful API不必与持久性/数据库方法完全相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM