I have a RESTful API that uses limit
& offset
to handle pagination (as described here). Each request also returns the total number of items available in order to allow clients to display pagination properly.
I'm wondering how to handle calls where the offset exceeds the total number of items. I can detect that case easily, because the total count is checked before fetching any records - which allows me to skip the record fetching call as a micro-optimisation, as I know it will return nothing.
I see two options:
- Business as usual: I return a standard response, but with an empty array of items.
- 404: No results were found matching this request. This has the advantage of allowing me to send an empty body, but also has the ambiguity that the endpoint is not valid.
I'm not sure which option to go with, or if there is a better one.
Edit: It seems like the proper solution is to return a 204. It allows me to send an empty body, without the ambiguity of endpoint invalidity.