Manual Pagination Challenge

📝 Table of Contents

📙 About

A single endpoint app built using the Express framework and the Node environment without the use of external libraries.

Process

  1. Set up Express and Node environment with server listening on port 3000
  2. Installed necessary dependencies in package.json
  3. Created dummy data using loops
  4. Created endpoint, added manual pagination, and incorporated sorting functionality
  5. Deployed to Heroku

Queries and Pagination

Using queries added onto the "/apps" endpoint allows us to specify which page we would like to view while limiting the number of data entries printed per page. Sort and order query params were added to allow us to organize the displayed data based on the id or name of the app and in an ascending or descending format. The query parameter (req.query) is used over the path parameter (req.param) as it is best practice when sorting or filtering data. If no queries are specified in the URI, built-in default values keep everything running smoothly. A check is also implemented to show the previous and next pages, if available, and how many entries will be shown on those pages.

⚙️ Setup

Installation

  • Clone the repo
  • Install the server dependencies with: npm install or yarn install
  • Run the local backend server using npm start or yarn start
  • Open http://localhost:3000 and start entering your test queries into the URI

📡 Endpoints

GET /apps

Example Queries
https://manual-pagination.herokuapp.com/apps
https://manual-pagination.herokuapp.com/apps?page=1
https://manual-pagination.herokuapp.com/apps?page=2&limit=5
https://manual-pagination.herokuapp.com/apps?page=1&sortBy=name&orderBy=desc
https://manual-pagination.herokuapp.com/apps?page=2&limit=3&sortBy=name&orderBy=desc
Query Parameters Type Default Description
page Number 1 Paginates to the requested page.
limit Number 50 Limits number of entries per page.
sortBy String "id" Only accepts "id" or "name".
orderBy String "asc" Enter 'asc' for ascending order or 'desc' for descending order.

⛏️ Built Using

✍️ Authors