WayrApp Backend & Ecosystem Documentation - v1.0.0
    Preparing search index...

    Function addPaginationHeaders

    • Adds comprehensive pagination metadata to HTTP response headers.

      This function enriches the HTTP response with pagination information including traditional page-based headers, offset-based headers, and RFC 5988 compliant Link headers for API navigation. It automatically calculates next/previous offsets and constructs proper URLs for pagination links.

      The function adds both standard pagination headers (X-Total-Count, X-Current-Page) and modern offset-based headers (X-Offset, X-Next-Offset) to support different client pagination strategies. Link headers provide direct navigation URLs for first, last, next, and previous pages.

      Parameters

      • res: Response

        Express response object to add headers to

      • pagination: any

        Pagination metadata object containing page, limit, total, totalPages, hasNext, and hasPrev properties

      Returns void

      // Usage in controller after service call
      const result = await courseService.getCourses(queryOptions);
      addPaginationHeaders(res, result.pagination);
      res.json({ data: result.data, success: true });