views:

667

answers:

8

I was wondering what peoples opinions are of a RESTful 'PUT' operation that returns nothing(null) in the response body?

A: 

Ideally it would return a success/fail response.

altCognito
Not in the response body, though. The HTTP status code is the place for that. Maybe if there's an error some extended error information could be returned in the response bidy
Paul
+9  A: 

I don't see a problem with that, as long as you return an appropriate HTTP response code. 201 Created is probably the most suitable in this case.

Emil H
From the link cited: "The request has been fulfilled and resulted in a new resource being created." PUT tends to be an update method, whereas POST is the create method. There's no problem with not returning a representation in the response body for a PUT, but I'd return 200 OK instead.
Rich Apodaca
A: 

seems ok... though I'd think a rudimentary indication of success/failure/time posted/# bytes received/etc. would be preferable.

edit: I was thinking along the lines of data integrity and/or record-keeping; metadata such as an MD5 hash or timestamp for time received may be helpful for large datafiles.

Jason S
How about 200 OK in the status response header? Do think thats enought to say, "Worked fine thanks?"
AnthonyWJones
the response header would contain the status code, and yes we are talking about HTTP at this point :)
AWC
+1  A: 

The HTTP/1.1 spec (section 9.6) discusses the appropriate response/error codes. However it doesn't address the response content.

What would you expect ? A simple HTTP response code (200 etc.) seems straightforward and unambiguous to me.

Brian Agnew
A: 

Just as an empty Request body is in keeping with the original purpose of a GET request and empty response body is in keeping with the original purpose of a PUT request.

AnthonyWJones
A: 

There's a difference between the header and body of a HTTP response. PUT should never return a body, but must return a response code in the header. Just choose 200 if it was successful, and 4xx if not. There is no such thing as a null return code. Why do you want to do this?

AlexanderJohannesen
A: 

As opposed to most of the answers here, I actually think that PUT should return the updated resource (in addition to the HTTP code of course).

The reason why you would want to return the resource as a response for PUT operation is because when you send a resource representation to the server, the server can also apply some processing to this resource, so the client would like to know how does this resource look like after the request completed successfully. (otherwise it will have to issue another GET request).

LiorH
+2  A: 

The HTTP specification (RFC 2616) has a number of recommendations that are applicable. Here is my interpretation:

  • HTTP status code 200 OK for a successful PUT of an update to an existing resource. No response body needed. (Per Section 9.6, 204 No Content is even more appropriate.)
  • HTTP status code 201 Created for a successful PUT of a new resource, with URIs and metadata of the new resource echoed in the response body. (RFC 2616 Section 10.2.2)
  • HTTP status code 409 Conflict for a PUT that is unsuccessful due to a 3rd-party modification, with a list of differences between the attempted update and the current resource in the response body. (RFC 2616 Section 10.4.10)
  • HTTP status code 400 Bad Request for an unsuccessful PUT, with natural-language text (such as English) in the response body that explains why the PUT failed. (RFC 2616 Section 10.4)
system PAUSE