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 :)
Successful responses ( 200 – 299 ) Redirection messages ( 300 – 399 ) Client error responses ( 400 – 499 ) Server error responses ( 500 – 599 )
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.
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.
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.
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".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With