Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

201 Created or 303 See Other after a POST request

Tags:

rest

From a RESTful interface, what should be the best status code after a successful POST action?

  • 201 Created
  • 303 See Other

Note: considering in the HTTP server answer, the Location key can be present.

I'm confused. Thanks for any answers.

like image 314
T5i Avatar asked Nov 10 '13 21:11

T5i


People also ask

What is a 303 response code?

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.

What does HTTP Status 201 created indicate in restful API?

The HTTP 201 Created success status response code indicates that the request has succeeded and has led to the creation of a resource.

What should 201 created return?

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.


1 Answers

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.

like image 185
Rich Remer Avatar answered Sep 21 '22 16:09

Rich Remer