I know this is a fairly common question, but I did not find an answer that satisfies me.
I have been using the django rest framework for a long time, but it basically does not matter, except for the above example. Its default behavior is to return HTTP 200 with an empty list resource when accessing a route with an empty list of elements. For example: if we had a route, for example /articles/ , to access the list of articles, but there were no elements in it, we would get an answer like the following json:
{"count":0, "next":null, "previous":null, "items": []}
It's fine. We found the resource we were looking for in / articles /, it just doesn’t have any elements.
If we get access to the /articles/?page=1 route, we get the same answer.
So far so good. Now we are trying to access /articles/?page=2 , and the response code changes. Now get 404 as if the resource could not be found with an error message stating that the page does not contain results. Is this the same case as with? Page = 1 ...
I was fine with this behavior, but today I started asking about this design. What is the case ?page=1 different from ?page=2 ? And what else, how could you say if the request was “valid” when issuing the HEAD request? Acts in the sense of the content of any results.
This can be useful in cases such as filtering a list that checks for the availability of a specific field (for example, issuing a HEAD request to /users/?username=ted ).
- A response of 200 explicitly means that the request was understood and the elements were found.
- A 404 will mean that the request was understood, but no elements were found at this location / URI (AFAIK request parameters are also part of the URI).
- If the query cannot be understood, 400 will be returned for syntax errors and 422 for semantic errors.
Is this a good design? Why do most people seem to disagree with this, and what are the flaws in it?