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:
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.
As I stated in the other answer, I would use one of:
I think it's safe to return an error (4xx + error info) in this situation because the offset can be exceeded by one of these assumptions:
HTTP 204 in pagination response is not factible because of the payload. When paginating you should return pagination information like, items returned, total items, offset, etc. which is not allowed with HTTP 204.