Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opinions Needed on the Atomicity of a RESTful PUT

Tags:

rest

http

My colleagues and I are implementing a number of RESTful HTTP services, and we're trying to make sure we are a) following the spec, and b) doing the "right" thing where the spec is short of detail.

Here is a particular situation that we have come to and are looking for opinions from the community on:

Suppose you have a resource /People/Bob, and your client is going to update it with a PUT. The server can produce representations for /People/Bob in application/json and text/html. The server can interpret representations for /People/Bob in application/json.

Given this request:

PUT /People/Bob
Content-Type: application/json
Accept: application/xml

{ name: "Still Bob" }

The server can't produce an XML representation, but it can process the incoming JSON. So we know the correct answer is for the server to return status 406.

The question is: should the server have performed the update to /People/Bob?

like image 473
theguidry Avatar asked Sep 22 '09 14:09

theguidry


1 Answers

+1 for Philosophy of REST.

Without detailed knowledge of the HTTP spec, I would simply choose one of the options and document the quandary and the choice.

My preference would be that the server cannot respond as requested, then it should not process any of the request at all.

But that may not work in some scenarios, so you might have to do the opposite.

like image 173
yfeldblum Avatar answered Oct 05 '22 05:10

yfeldblum