I know there is no clear consensus in the web community about this subject, so my issue is mainly to know the opinion of Rails core about this, especially @josevalim who last touched the code in 80768b.
When generating a RESTful controller with rails g scaffold
, the JSON part of the update method (responding to PUT/PATCH) looks like this:
if @item.update(item_params)
head :no_content
else
render json: @item.errors, status: :unprocessable_entity
end
Therefore, in order to get the whole changed object, another request must be sent to the show method (GET).
Responding with :ok and an object representation might save this extra request. Citing Vinay Sahni’s Best Practices for Designing a Pragmatic RESTful API:
A PUT, POST or PATCH call may make modifications to fields of the underlying
resource that weren’t part of the provided parameters (for example: created_at or
updated_at timestamps). To prevent an API consumer from having to hit the API
again for an updated representation, have the API return the updated (or created)
representation as part of the response.
Rails already behaves in this way for POST (create method). Would you accept a pull request that changed the behavior of the scaffold generator to have PUT and PATCH (update method) also return the full object representation?