class

Pika::API

Inherits Reference < Object

Class methods

paginate(collection : Clear::Model::Collection, using entity_class, page : Int32 = 1, per_page : Int32 = 25, **opts) : String

paginate — apply page/per_page query params to a Clear collection and return a JSON object with data and meta keys.

Usage (inside a handler, after params_from or a manual params block that declares page and per_page as optional Int32 params):

resource :users do params do optional page : Int32 = 1 optional per_page : Int32 = 25 end get do paginate(User.query, declared_params.page, declared_params.per_page) end end

Returns a JSON string: {"data":[...],"meta":{"total":N,"page":P,"per_page":Q,"pages":R}}

Source