Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In REST, should I return the representation in response to a PUT?

Tags:

It is conceivable that another client also modified other aspects of the resource in the interim. So is it best practice to always include the full representation in the response to a PUT, despite the bandwidth overhead?

like image 410
Kevin Pauli Avatar asked Jan 14 '10 16:01

Kevin Pauli


1 Answers

In many (if not most) cases, the server will add something to the resource even if it's created or updated via PUT. Examples are timestamps, a version number, or any element computed from others. This is true even if you follow the RESTful approach and do not use PUT for partial updates.

For this reason alone, returning the updated or created resource's representation is often a good idea for PUT requests. I wouldn't necessarily call it a "best practice", though – if you PUT a giant 2GB image file you probably do not want to return it as part of the response.

Including an ETag, on the other hand, definitely deserves "best practice" status.

like image 101
Stefan Tilkov Avatar answered Oct 04 '22 19:10

Stefan Tilkov