Forem Creators and Builders 🌱

Cover image for Pagination response suggestion 🚀
Lazar Stankovic
Lazar Stankovic

Posted on

Pagination response suggestion 🚀

Table Of Contents


Hello, everybody. I hope you are all having a great day coding!🔥
I was just starting my personal project for my web presentation (portfolio/presentation/store) project, and I am using the Dev API to get my articles and reference them on my website. Everything went ok, I was getting articles using this endpoint with my username:


I have a total of 12 articles written on the Dev platform. Of course, the above endpoint gets everything I need, 4 articles per page (current page is 1); I was trying to make a custom pagination. I was looking through the response I got from an API: (Response body structure, taken from Dev API)

    "type_of": "article",
    "id": 194541,
    "title": "There's a new DEV theme in town for all you 10x hackers out there (plus one actually useful new feature)",
    "description": "",
    "cover_image": ",f_auto,fl_progressive,h_420,q_auto,w_1000/",
    "readable_publish_date": "Oct 24",
    "social_image": ",f_auto,fl_progressive,h_500,q_auto,w_1000/",
    "tag_list": [
    "tags": "meta, changelog, css, ux",
    "slug": "there-s-a-new-dev-theme-in-town-for-all-you-10x-hackers-out-there-plus-one-actually-useful-new-feature-2kgk",
    "path": "/devteam/there-s-a-new-dev-theme-in-town-for-all-you-10x-hackers-out-there-plus-one-actually-useful-new-feature-2kgk",
    "url": "",
    "canonical_url": "",
    "comments_count": 37,
    "positive_reactions_count": 12,
    "public_reactions_count": 142,
    "collection_id": null,
    "created_at": "2019-10-24T13:41:29Z",
    "edited_at": "2019-10-24T13:56:35Z",
    "crossposted_at": null,
    "published_at": "2019-10-24T13:52:17Z",
    "last_comment_at": "2019-10-25T08:12:43Z",
    "published_timestamp": "2019-10-24T13:52:17Z",
    "user": {
      "name": "Ben Halpern",
      "username": "ben",
      "twitter_username": "bendhalpern",
      "github_username": "benhalpern",
      "website_url": "",
      "profile_image": ",f_auto,fl_progressive,h_640,q_auto,w_640/",
      "profile_image_90": ",f_auto,fl_progressive,h_90,q_auto,w_90/"
    "organization": {
      "name": "The DEV Team",
      "username": "devteam",
      "slug": "devteam",
      "profile_image": ",f_auto,fl_progressive,h_640,q_auto,w_640/",
      "profile_image_90": ",f_auto,fl_progressive,h_90,q_auto,w_90/"
Enter fullscreen mode Exit fullscreen mode

As you can see there is no data in this response about the pagination and by that I mean, for example:

  • first page (1)
  • current page (1)
  • next page (If page=1 then next page is 2)
  • total items (Example: total number of articles is 12)
  • last page (if per_page is 4 and total items is 12 then the last page is 3)

This response data will make it possible to implement actual pagination. It will make it clear that in total I have 12 articles, and since my per_page is 4, it is easily calculable that I would have 3 pages (3 pagination buttons) that will contain 4 articles per page. For now, I cannot determine how many articles I have in total If I make a GET request with pagination parameters, and that prevents me from implementing pagination.


Thank you for reading. Let me know what you think about this suggestion, or tell me if I am wrong about this and how can I solve this differently. Maybe, it is a work in progress, but I am new to forem.

Have a nice time hacking! 😊

Top comments (2)

rhymes profile image
rhymes • Edited

Hi @codespresso , thanks for taking the time to write this. Unfortunately we don't have pagination headers or information in the response or the response headers at the moment.

I understand it's a bit tricky to build a paginator on top of this.

What I could think of is to do a simple paginator with a CURRENT_PAGE..NEXT type of navigation and then decide to render the NEXT only if CURRENT_PAGE+1 returns results.

It's not great but it should work...

codespresso profile image
Lazar Stankovic

Thank you for your response @rhymes !

Sorry for my late answer, I was in the middle of moving to another city (remote work season is over). Of course, the idea is valid but not great, I could certainly make FE pagination while GETting all articles for a specific username that I could optimize to work fast.

This is just my suggestion and I have no doubts that in some future API releases we will have a perfect backend paginated response.

Thank you, again, for your answer and suggestion, and happy hacking!