Skip to content
API/JsonServerResponseStrategy

JsonServerResponseStrategy

src/strategies/json-server-response.strategy.ts1 public methodsclass

Response strategy for the json-server driver

Parses json-server v1 paginated responses:

{
"first": 1,
"prev": null,
"next": 2,
"last": 5,
"pages": 5,
"items": 48,
"data": [...]
}

Uniquely among the drivers, first / prev / next / last are page numbers, not URLs — so the navigation-URL slots on PaginatedCollection stay undefined and the strategy instead uses the numbers to derive position:

  • currentPage is prev + 1 (prev === null → page 1).
  • perPage is the item count of the current page whenever next is set (a page with a successor is necessarily full); on the last page of a multi-page set it is not introspectable and stays undefined.
  • lastPage comes straight from pages; from/to derive from currentPage × perPage on full pages, or count back from the total on the last page (from = total - items + 1, to = total).

The data / items / pages key paths are configurable through JsonServerResponseOptions; the prev / next keys are fixed by the json-server envelope and live as private statics.

new JsonServerResponseStrategy()
paginate(response: RawResponse, options: ResponseOptions): PaginatedCollection<T>

Parse a json-server pagination response into a PaginatedCollection

Parameter Type Description
response RawResponse The raw API response body
options ResponseOptions The response key name configuration

Returns — A typed PaginatedCollection instance