-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Pagination normalization for _per_page=0 is unclear #1721
Description
Description
I noticed an unclear pagination behavior when _per_page=0 is provided.
According to the documentation:
Invalid
_pageor_per_pagevalues 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 devThen send the request:
GET http://localhost:3000/posts?_page=1&_per_page=0Observed 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=0to1 - 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.