SpringResponseStrategy
Response strategy for the Spring Data REST driver
Parses Spring Data REST’s HAL envelope:
{ "_embedded": { "users": [{ "id": 1, "name": "John" }] }, "_links": { "first": { "href": "..." }, "prev": { "href": "..." }, "next": { "href": "..." }, "last": { "href": "..." } }, "page": { "size": 20, "totalElements": 100, "totalPages": 5, "number": 1 }}Two HAL quirks are absorbed here on top of the inherited dot-path traversal:
page.numberis 0-indexed — the strategy adds 1 so the library state stays 1-indexed (mirroringSpringRequestStrategy, which subtracts 1 on the way out).- The collection key under
_embeddedis the resource rel name (e.g._embedded.users), which cannot be known statically. The defaultdatapath is plain_embedded; when it resolves to an object rather than an array, the strategy picks the first array value inside it. Consumers with multiple embedded rels can pin the exact path viaConfig.response(e.g.data: '_embedded.users').
Default key paths are configured in SpringResponseOptions.
Constructor
Section titled “Constructor”new SpringResponseStrategy()Methods
Section titled “Methods”paginate()
Section titled “paginate()”paginate(response: RawResponse, options: ResponseOptions): PaginatedCollection<T>Parse a Spring Data REST HAL 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
resolve()
Section titled “resolve()”resolve(response: RawResponse, path: string): unknownResolve a value from a response object using a dot-notation path
Supports both flat keys ('data') and nested paths ('meta.totalItems').
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw response object |
path |
string |
The dot-notation path to resolve |
Returns — The resolved value, or undefined if any segment is missing
resolveFrom()
Section titled “resolveFrom()”resolveFrom(response: RawResponse, options: ResponseOptions, currentPage: number, perPage?: number): number | undefinedResolve the “from” index value
If options.from resolves to a value in the response, use it.
Otherwise compute (currentPage - 1) * perPage + 1 when both are known.
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw response object |
options |
ResponseOptions |
The response key name configuration |
currentPage |
number |
The current page number |
perPage |
number |
The number of items per page |
Returns — The “from” index, or undefined when neither path nor inputs suffice
resolveTo()
Section titled “resolveTo()”resolveTo(response: RawResponse, options: ResponseOptions, currentPage: number, perPage?: number, total?: number): number | undefinedResolve the “to” index value
If options.to resolves to a value in the response, use it.
Otherwise compute Math.min(currentPage * perPage, total) when all
three are known.
| Parameter | Type | Description |
|---|---|---|
response |
RawResponse |
The raw response object |
options |
ResponseOptions |
The response key name configuration |
currentPage |
number |
The current page number |
perPage |
number |
The number of items per page |
total |
number |
The total number of items |
Returns — The “to” index, or undefined when neither path nor inputs suffice
