Pagination is a technique used to divide a large set of data into smaller, manageable chunks, or “pages.” This is particularly useful in web applications to improve performance and enhance user experience by loading data incrementally.

Using page and perPage Parameters

To implement pagination, two key parameters are commonly used:

  • page: Indicates the current page number.
  • perPage: Specifies the number of items to display per page.

Example Usage

Assume you have an API endpoint that returns a list of items. You can use the page and perPage parameters to control the pagination:

// Example API request in JavaScript
const page = 1; // Current page number
const perPage = 10; // Number of items per page

fetch(`https://api.woodcore.co/items?page=${page}&perPage=${perPage}`)
  .then(response => response.json())
  .then(data => {
    console.log(data);
  });

In this example, the API request fetches the first page of items, with 10 items per page. Adjusting the page and perPage values allows you to navigate through the dataset efficiently.

Conclusion Pagination is an essential technique for managing large datasets in web applications. By using the page and perPage parameters, you can easily control the amount of data displayed and improve the overall performance and user experience of your application.