Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When Updating a resource, what HTTP Status Code is returned when the update is successful?

So i've got a website that accepts an HTTP-PUT for a particular resource, eg. /contact which will allow the consumer to update a contact, assuming they have passed validation.

So I update the record, all is great .. and now I need to return something to the consumer.

What's the HTTP Status Code I should be returning?

If this was an HTTP-POST (ie. Creating a -new- resource), then I would return an 201 Created and add a Location header attribute.

But .. I can't find any clues about what to do for an Update.

Cheers :)

like image 329
Pure.Krome Avatar asked May 08 '12 11:05

Pure.Krome


People also ask

What is the HTTP status return code for a successful?

Successful responses ( 200 – 299 ) Redirection messages ( 300 – 399 ) Client error responses ( 400 – 499 ) Server error responses ( 500 – 599 )

Should POST return 200 or 201?

The POST method is used to send data to the server. Perhaps the most common status code returned is 200. It simply means that the request was received, understood, and is being processed, whereas the 201 status code indicates that a request was successful and a resource was created as a result. 1.

Should Put return 200 or 204?

200 OK - This is the most appropriate code for most use-cases. 204 No Content - A proper code for updates that don't return data to the client, for example when just saving a currently edited document.

Which HTTP status code is returned after a successful REST API request?

The HTTP 204 status code is used when the request sent by the client has been successfully processed by the server but there is no content to be returned to the client. The user is expected to send a request for old or different content.


1 Answers

200 is especially appropriate if you are returning a representation of the action (although the work-in-progress-but-nearing-last-call "HTTP bis" oddly doesn't mention PUT in its description of 200 OK).

If you're not returning any sort of representation, use 204 No Content to indicate to the client that it doesn't need to change its current "document view".

like image 127
fumanchu Avatar answered Sep 30 '22 01:09

fumanchu