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<https://github.com/rails/rails/commit/80768b739ed7e2053d85a01dd5fa60bde67aad9a>
.
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<http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api#useful-post-responses>
:
> 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?
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.