In this episode, I will show you how to add pagination to a resource listing API in the API-only Rails application that we created in Episode #3. Also, the application will be run on docker using docker-compose. I will be using Kaminari gem to implement pagination.
There are two approaches to add pagination data in the API response – first is to add the pagination metadata (total count, links to the next, previous, first, last page, etc) in the JSON response body, and the second approach using HTTP response headers. My preference is the HTTP response header which is explained in this video.