Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davestewart's avatar

REST purity - 200 OK vs 201 created

Outline

We have a web app (SPA) where on one of the pages, the user can edit and submit a list of items (stock codes, quantities).

This is done using a Grid component, like Google Sheets, and works great.

As the user types, we do GET requests to populate additional columns with information such as price calculations, descriptions, etc, etc.

The user can then set a name for the list, then POST the whole thing as JSON.

Additional functionality - file upload

However, the user can also upload a CSV or XLS with the codes and quantities.

We have it set up so as soon as the user selects a file it uploads transparently in the background, and the the list is populated with the result. This works very similarly to how it works when typing.

Problem

However, the developer in charge of this feature wants to change the implementation and says we must submit the name and file without any background upload, then and then redirect to the edit/:id version of the URL to see the results and continue.

Apparently, the way we are doing it now is not proper REST (he says it doesn't create a resource and so he won't return the converted results) and he is refusing to back down on the matter even though the users love it.

This results in a poor UX for the user because if they want to use a file, they HAVE to fill out the whole form, create a resource, and redirect.

Bear in mind, this is an SPA so we don't have the same constraints as a regular HTML form on the front end.

So...

What's the deal here?

Surely returning a 200 with the results of the POST to a related endpoint would be OK?

If not, is there some way we can do this that will not offend his "pure" sensibilities?

Would appreciate some impartial input, thanks.

0 likes
1 reply
davestewart's avatar

So I think I have answered my own question:

9 Method Definitions > 9.5 POST

https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.5

The actual function performed by the POST method is determined by the server and is usually dependent on the Request-URI.

The posted entity is subordinate to that URI in the same way that a file is subordinate to a directory containing it, a news article is subordinate to a newsgroup to which it is posted, or a record is subordinate to a database.

The action performed by the POST method might not result in a resource that can be identified by a URI.

In this case, either 200 (OK) or 204 (No Content) is the appropriate response status, depending on whether or not the response includes an entity that describes the result.

HTTP POST

https://restfulapi.net/idempotent-rest-apis/

Generally not necessarily POST APIs are used to create a new resource on server.

Please or to participate in this conversation.