Skip to content

json-server

driverjson-server4/8 capabilities

Import the driver directly so the other seventeen tree-shake away.

json-server.ts
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({}),
);
qb.setResource('articles')
.addFilter('status', 'published')
.addSort('createdAt', SortEnum.DESC)
.setLimit(25)
.generateUri();

Produces:

/articles?status=published&_sort=-createdAt&_page=1&_per_page=25
Capability Supported
Filters
Operators
Sort
Select
Fields
Includes
Search
Embedded
const body = await fetch(`https://example.com/api${uri}`).then((r) => r.json());
const page = paginator.paginate(body);
page.data; // rows
page.total; // total rows the backend reported
page.lastPage; // final page number