django-rest-framework-link-header-pagination icon indicating copy to clipboard operation
django-rest-framework-link-header-pagination copied to clipboard

Include total count in response

Open johnnymetz opened this issue 2 years ago • 2 comments

Background

The Link HTTP header only includes links to different pages. It would be great to also include the total count somewhere in the response.

Potential Solution

This SO answer suggests including an X-Total-Count header in the response.

I'm happy to work on this if you don't have time to do it.

Workaround

I understand I can calculate this using the following steps but it includes an extra API call:

  • Hit the last url
  • Calculate the number of items in the last response
  • Perform the simple calculation: PAGE_SIZE * (LAST_PAGE_INDEX - 1) + NUM_ITEMS_ON_LAST_PAGE

For example: If I have 25 items with a page size of 10, the calculation would be:

10 * (3 - 1) + 5 = 25

johnnymetz avatar Oct 10 '22 17:10 johnnymetz

+1

Considering the performance issue, it is suggested to add a setting option to control the on/off switch of this feature.

xyb avatar Mar 18 '23 18:03 xyb

I am looking forward for a feature like this, when this feature is going to be released ?

deshneni-akhil avatar Oct 05 '23 00:10 deshneni-akhil