简体   繁体   中英

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 ?

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 ?

PUT replaces the resource pointed to by the URL.
PATCH modifies the resource pointed to by the URL.

If you are modifying some subset of the properties of a resource, then PATCH is appropriate.

Just because PUT replaces an object in full doesn't mean you have to expose all fields for update. If you want create and updated dates done only on the backend, then do not expose them in either your PUT or PATCH methods.

Your RESTful API does not have to be exactly the same as your persistence/database methods.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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