Should all the fields of a resource and its related resources be passed in a REST API PUT request? -


let's have ticket & comment resource. tickets can have many comments. in update endpoint http put /api/tickets/<ticket_id>/ , should require client pass fields of ticket + comments when updating ticket?

i asked developers , of them said should pass fields modified since lighter, faster in terms of performance , easier use. , said should pass fields of ticket + comments since put request should idempotent. concern when there many comments, payload big.

yes, since put request should replace entity-to-update in it's entirety. if want partial update of entity, use patch request.

also see the rfc reference

patch method http

several applications extending hypertext transfer protocol (http) require feature partial resource modification.

the existing http put method allows complete replacement of document. proposal adds new http method, patch, modify existing http resource.

so in situation, it's lot more efficient use patch request partial update.


Comments