Should Scaffold generate PUT/PATCH methods that respond with 200 OK (rather than 204 No Content)?

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?

I am strongly in favor of this change. I didn’t realize the scaffold was not returning the whole changed object for update, but I believe it should. For consistency with the other methods and for the convenience of the caller. As you point out, without this change the caller will have to make another HTTP round-trip when they want the complete, updated object (including any server-side side-effects that may have been applied).

Brian Morearty

I feel like we had discussed this before, but am not 100% sure. I do think that this change is nice, but not mandatory. I'm neutral to mildly positive about this.

Well, in case you tend more for the “mildly positive”, I’ve submitted a pull request: https://github.com/rails/rails/issues/12096#issuecomment-23834726