Transforms REST-style pagination params to Flop format and vice versa.
Supports three pagination types:
- Cursor-based:
limit,after,before - Page-based:
page,page_size - Offset-based:
offset,limit
When only limit is provided, it defaults to cursor-based pagination
(first). This ensures Flop returns cursor metadata that can be used
for subsequent requests with after/before. To force
offset-based pagination, include offset (e.g., offset=0).
No validation is performed - conflicting params are passed through for Flop to validate.
Summary
Functions
Returns the list of reserved pagination keys.
Converts a Flop struct's pagination fields back to REST-style params.
Transforms pagination parameters to Flop format.
Functions
@spec reserved_keys() :: [String.t()]
Returns the list of reserved pagination keys.
Converts a Flop struct's pagination fields back to REST-style params.
Examples
iex> FlopRest.Pagination.to_rest(%Flop{first: 20, after: "abc"})
%{"limit" => 20, "after" => "abc"}
iex> FlopRest.Pagination.to_rest(%Flop{last: 20, before: "xyz"})
%{"limit" => 20, "before" => "xyz"}
iex> FlopRest.Pagination.to_rest(%Flop{page: 2, page_size: 25})
%{"page" => 2, "page_size" => 25}
iex> FlopRest.Pagination.to_rest(%Flop{offset: 50, limit: 25})
%{"offset" => 50, "limit" => 25}
iex> FlopRest.Pagination.to_rest(%Flop{})
%{}
Transforms pagination parameters to Flop format.
Examples
iex> FlopRest.Pagination.transform(%{"limit" => "20", "after" => "abc"})
%{"first" => 20, "after" => "abc"}
iex> FlopRest.Pagination.transform(%{"limit" => "20"})
%{"first" => 20}
iex> FlopRest.Pagination.transform(%{"page" => "2", "page_size" => "25"})
%{"page" => 2, "page_size" => 25}
iex> FlopRest.Pagination.transform(%{"offset" => "0", "limit" => "25"})
%{"offset" => 0, "limit" => 25}