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:
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.
Description
I noticed an unclear pagination behavior when
_per_page=0is provided.According to the documentation:
However, the behavior for
_per_page=0is not clearly defined.The request succeeds and returns paginated results instead of rejecting the value or clearly documenting the normalization rule.
Environment
Steps to reproduce
Run the current repository version with the default fixtures:
Then send the request:
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 indata.Example response:
{ "first": 1, "prev": null, "next": 2, "last": 2, "pages": 2, "items": 2, "data": [ { "id": "1", "title": "a title" } ] }This suggests
_per_page=0is 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=0should normalize to.Possible expectations could include:
_per_page=0to1400 Bad Request)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=0would make the API behavior clearer and more predictable.