JSON:API
driverjson-api4/8 capabilities
Import the driver directly so the other seventeen tree-shake away.
import { JSON_API_DRIVER, QubeeStore, QueryBuilder, Paginator } from '@qubeejs/core';
const store = new QubeeStore();const qb = new QueryBuilder(store, JSON_API_DRIVER.createRequestStrategy('query'));const paginator = new Paginator( store, JSON_API_DRIVER.createResponseStrategy(), JSON_API_DRIVER.createResponseOptions({}),);Example query
Section titled “Example query”qb.setResource('articles') .addFilter('status', 'published') .addSort('createdAt', SortEnum.DESC) .setLimit(25) .generateUri();Produces:
/articles?filter[status]=published&page[number]=1&page[size]=25&sort=-createdAtCapabilities
Section titled “Capabilities”| Capability | Supported |
|---|---|
| Filters | ✅ |
| Operators | — |
| Sort | ✅ |
| Select | — |
| Fields | ✅ |
| Includes | ✅ |
| Search | — |
| Embedded | — |
Reading a response
Section titled “Reading a response”const body = await fetch(`https://example.com/api${uri}`).then((r) => r.json());const page = paginator.paginate(body);
page.data; // rowspage.total; // total rows the backend reportedpage.lastPage; // final page number