Closed peveuve closed 7 years ago
I'm not sure I understand everything you're proposing here, can you be more specific ?
If I understood correctly:
The status code is an option but the HTTP headers related to pagination should not be included if the full data has been sent ?
For example you are paginating with a limit of 10 but there is only 5 items, you should return 200 and don't include the header ?
Yes, return 200 and no headers if all dataset is returned, return 206 and both headers if only a part of the dataset is returned. It would mean the successStatusCode option I added recently would be useless, and developers couldn't set one of their own.
After some thoughts, my view is the following now: We can deduce that the result has been paginated by comparing totalCount with result.lenght, so we could set the status code ourselves: 206 if the result is paginated, keep the status code otherwise. In case of pagination (206), the plugin should set the headers in the response. In other cases, it shouldn't.
We should take in account the case where the server wants to redirect the user to another page where the result lies (3XX status codes). So we shouldn't set the status code unless the data is there and partial, and we should take care of not failing if there is no data in the response body.
Overall, I agree it can be annoying to set the status code, so we could just skip the headers if not 206.
I am not sure it is interesting for the plugin, but it's worth wondering : The HTTP recommendation is to return 200 when the full data is returned and 206 when a part of the data is returned. In the same logic, we should not send the HTTP headers related to pagination in case of 200. We could implement this in the plugin but it would force the response status code whatever the developer decides on his side. What do you think?