class Orion::API::Paginator(T)

Overview

Pagination helper for APIs Supports offset/limit and cursor-based pagination

Usage:

In controller

paginator = Orion::API::Paginator.new( collection: users, page: params["page"]?.try(&.to_i) || 1, per_page: 25 )

render json: { data: paginator.items, pagination: paginator.meta }

Defined in:

orion/api/pagination.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(collection : Array(T), page : Int32 = 1, per_page : Int32 = 25, total_count : Int32 | Nil = nil) #

Instance Method Detail

def collection : Array(T) #

def collection=(collection : Array(T)) #

def first_page? : Bool #

def has_next? : Bool #

def has_prev? : Bool #

def items : Array(T) #

Get paginated items


def last_page? : Bool #

def link_headers(base_url : String, params : HTTP::Params = HTTP::Params.new) : String #

Get link headers (RFC 5988)


def meta : Hash(String, Int32 | Bool) #

Get pagination metadata


def next_page : Int32 #

def page : Int32 #

def page=(page : Int32) #

def per_page : Int32 #

def per_page=(per_page : Int32) #

def prev_page : Int32 #

def total : Int32 #

def total_count : Int32 | Nil #

def total_count=(total_count : Int32 | Nil) #

def total_pages : Int32 #