Let say we have only 30 products and a REST API with QueryString parameters used for pagination. In the exemple below pagesize
is the number of resources per page
.
api/products?page=1pagesize=10
What do you prefer to answer when the request is asking for a page over the max page like the following?
api/products?page=125&pagesize=10
The limit option allows you to limit the number of rows returned from a query, while offset allows you to omit a specified number of rows before the beginning of the result set. Using both limit and offset skips both rows as well as limit the rows returned.
You can paginate the JSON response that is called from the REST API. The order of the data is retained from page to page. Given the ability to paginate, you can quickly populate tables and make new REST calls every time you go to the next page of the data on the table.
The benefits of this approach is that it doesn't require additional backend logic. It only requires one limit URL parameter. It also features consistent ordering, even when new items are added to the database. It also works smoothly with large offset values.
The best way to build API pagination in a safe way is for the API to return a “cursor”, or opaque string, with the list of results. This token is usually called next or next_cursor or starting_after This token can be passed with the next API request to request the next page.
I would go with Not Found, since the request's syntax is perfectly fine. See the status code explanations
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With