Skip to content

Pagination normalization for _per_page=0 is unclear #1721

@Omar-Tnt04

Description

@Omar-Tnt04

Description

I noticed an unclear pagination behavior when _per_page=0 is provided.

According to the documentation:

Invalid _page or _per_page values are automatically normalized to valid ranges.

However, the behavior for _per_page=0 is not clearly defined.

The request succeeds and returns paginated results instead of rejecting the value or clearly documenting the normalization rule.


Environment

  • json-server: v1.0.0-beta.6
  • Node.js: v24.12.0
  • OS: Windows 11

Steps to reproduce

Run the current repository version with the default fixtures:

pnpm dev

Then send the request:

GET http://localhost:3000/posts?_page=1&_per_page=0

Observed behavior

The request succeeds and returns a paginated response.

For example, using the default fixtures/db.json, the response includes pagination metadata and returns one item in data.

Example response:

{
  "first": 1,
  "prev": null,
  "next": 2,
  "last": 2,
  "pages": 2,
  "items": 2,
  "data": [
    {
      "id": "1",
      "title": "a title"
    }
  ]
}

This suggests _per_page=0 is internally normalized to a non-zero value.


Expected behavior

Since the documentation states that invalid values are normalized, it would help clarify what _per_page=0 should normalize to.

Possible expectations could include:

  • Normalizing _per_page=0 to 1
  • Returning an error (e.g. 400 Bad Request)
  • Falling back to the default pagination value

Currently the behavior appears to normalize silently, but the exact rule is not clearly documented.


Notes

This may be intended behavior, but documenting the normalization rule for _per_page=0 would make the API behavior clearer and more predictable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions