Pagination using FrontQL
Introduction
In web applications, it is common to retrieve data in pages. FrontQL provides the ability to paginate data using the page query parameter.
In FrontQL, pagination is a crucial component of data retrieval and pagination functionality. Pagination is used to retrieve data in pages. The page query parameter is used to specify the page number and the number of items per page.
Implementing Pagination
- The
pagequery parameter is used to specify the page number and the number of items per page. - There are two parameters in the
pageparameter:pageandlimit. pageis the page number andlimitis the number of items per page.pageandlimitare separated by a comma.
Example
async function getUsers() { const response = await Api.get("/users", { page: "1,15", // here, page = 1, limit = 15 });
return response;}async function getUsers() { const url = `${BASE_URL}/users?page=1,15`; // Replace BASE_URL with the base URL of API server const response = await fetch(url, { method: "GET", headers: { "Content-Type": "application/json", app: DATABASE, // Replace DATABASE with the name of your database token: TOKEN, // Replace TOKEN with the token // OR // Authorization: `Bearer ${AUTH_TOKEN}`, // Replace AUTH_TOKEN with the authorization token, } })
const data = await response.json(); return data;}This example uses the page query parameter to specify the page number and the number of items per page.