Response pagination for Fastify. Inspired by Django Rest Framework
npm install fastify-pagination
Or, if using yarn
:
yarn add fastify-pagination
const fastify = require('fastify')();
fastify
.register(require('fastify-pagination'))
.get("/", {}, async (request, reply) => {
const { limit, offset } = request.parsePagination();
const { items, count } = await getItemsAndTotalCountWithPagination(limit, offset);
reply.sendWithPagination({ count, page: items }); // adds `next` and `previous` properties.
});
Todo.