class
Orion::API::Paginator(T)
- Orion::API::Paginator(T)
- Reference
- Object
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.crConstructors
Instance Method Summary
- #collection : Array(T)
- #collection=(collection : Array(T))
- #first_page? : Bool
- #has_next? : Bool
- #has_prev? : Bool
-
#items : Array(T)
Get paginated items
- #last_page? : Bool
-
#link_headers(base_url : String, params : HTTP::Params = HTTP::Params.new) : String
Get link headers (RFC 5988)
-
#meta : Hash(String, Int32 | Bool)
Get pagination metadata
- #next_page : Int32
- #page : Int32
- #page=(page : Int32)
- #per_page : Int32
- #per_page=(per_page : Int32)
- #prev_page : Int32
- #total : Int32
- #total_count : Int32 | Nil
- #total_count=(total_count : Int32 | Nil)
- #total_pages : Int32
Constructor Detail
def self.new(collection : Array(T), page : Int32 = 1, per_page : Int32 = 25, total_count : Int32 | Nil = nil)
#
Instance Method Detail
Get link headers (RFC 5988)