Search code examples
restpaginationhttp-status-codes

In a REST API paginated resources: what would you return when a client request a page exceeding the maximum page number?


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
  1. 400 - Bad Request?
  2. 404 - Not Found?
  3. 200 - Ok (with empty result)?
  4. 204 - No Content?

Solution

  • I would go with Not Found, since the request's syntax is perfectly fine. See the status code explanations