Rufi
Rufi

Reputation: 2645

Should RESTful 'PATCH' operation return something?

I am struggling what is the best practice for PATCH method.

I see couple of possibilities:

  1. Return HTTP status code 200 OK with updated object.
  2. Return HTTP status code 204 No Content.

What would be the best one?

Upvotes: 8

Views: 5801

Answers (1)

Robert Bräutigam
Robert Bräutigam

Reputation: 7744

The specification states:

The 204 response code is used because the response does not carry a message body (which a response with the 200 code would have). Note that other success codes could be used as well.

Which just means you may decide to return a body or not, the response codes should then be 200 or 204 respectively. Neither is better or worse than the other. You may find that it is practical to just return the changed content, so the client does not have to make a new request to get the new content.

Note: using the PATCH is quite tricky, as you must define a mime-type for applying change-sets to your resource. This may not be what you want. More often than not, PATCH can be solved by just creating a new resource that should have been a resource anyway.

Upvotes: 8

Related Questions