12

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 :)

1
  • Very good question, looks like there's no standard HTTP code for this, so I'd just return a 200 OK. Commented May 8, 2012 at 11:23

2 Answers 2

20

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".

Sign up to request clarification or add additional context in comments.

3 Comments

What is the representation of the action? Is it representation of the updated resource or is it something along the lines of "Blablabla successfullly updated"
A representation of the action would be "blablabla successfully updated", usually only worthwhile if it includes a) details about what happened if useful to clients but especially b) links to what to do next
I don't agree. The representation of the action is, in my experience, usually the updated resource. While that may seem redundant at first (because you just sent that resource in the first place right?), it actually turns out that there are often derived/calculated fields on the resource like updatedAt fields etc that you cannot predict beforehand and so the server returns the updated resource with those derived fields included.
6

200 is the appropriate status code assuming the PUT only did an update and did not create a resource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.