json-server
driverjson-server4/8 capabilities
Import the driver directly so the other seventeen tree-shake away.
import { JSON_SERVER_DRIVER, QubeeStore, QueryBuilder, Paginator } from '@qubeejs/core';
const store = new QubeeStore();const qb = new QueryBuilder(store, JSON_SERVER_DRIVER.createRequestStrategy('query'));const paginator = new Paginator( store, JSON_SERVER_DRIVER.createResponseStrategy(), JSON_SERVER_DRIVER.createResponseOptions({}),);Example query
Section titled “Example query”qb.setResource('articles') .addFilter('status', 'published') .addSort('createdAt', SortEnum.DESC) .setLimit(25) .generateUri();Produces:
/articles?status=published&_sort=-createdAt&_page=1&_per_page=25Capabilities
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