Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do PUT request bodies have to contain an entire entity?

Tags:

rest

put

When defining a PUT method on a resource is it required/standard/customary to include the entire definition of the resource (i.e. everything needed to create it) or is it also acceptable to send only updated fields?

For example, if I have a resource with 10 attributes including one called quantity and I want to update the quantity to a specified value. Is it acceptable to PUT only the quantity?

What about the other 9 attributes? Assuming each attribute could be updated individually, is it good practice to define the request body simply to have all 10 attributes as optional?

like image 457
Peter Goodwine Avatar asked Apr 08 '11 00:04

Peter Goodwine


1 Answers

PUT when used RESTfully is intended to replace the entire resource, so you would want to include the full set of attributes.

That said, REST is used rather improperly in most cases anyway, and as long as your API is documented well, you can do whatever you deem most appropriate for your situation.

like image 108
Justin Waugh Avatar answered Sep 28 '22 06:09

Justin Waugh