From a RESTful interface, what should be the best status code after a successful POST action?
Note: considering in the HTTP server answer, the Location
key can be present.
I'm confused. Thanks for any answers.
A 303 See Other is an HTTP status code that indicates that the resource you requested is located at another URI (address) by using the GET HTTP method. In other words, it's a status response code informing you that the URL you're trying to access is redirecting you to another URL.
The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.
A successful creation (POST) of a resource has two potential response codes: If the resource was created immediately, a 201 Created response code is returned. If the resource is still being created, a 202 Accepted response code is returned.
201 Created
says "the resource is created and here's the URL of that resource".
303 See Other
says "nothing went wrong and you should check this URL for more information".
The primary distinction is that you would expect a conforming client to always GET
the URL from the Location
header in the case of a 303 See Other
. You would only expect a 201 Created
to result in a GET
on the URL if the client decides they need to fetch the resource from the server.
I would generally advise against sending a 303 See Other
for anything but web forms or if you have developed a multi-stage API, where you must perform subsequent requests after the first.
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