JSONAPIPlug.Pagination behaviour (jsonapi_plug v2.0.1)

View Source

JSON:API Pagination strategy

https://jsonapi.org/format/#fetching-pagination

Pagination links can be generated by implementing a module conforming to the JSONAPIPlug.Pagination behavior and configuring the pagination of your API module:

defmodule MyApp.MyController do
  plug JSONAPIPlug.Plug, api: MyApp.MyApi, resource: MyApp.MyResource
end
config :my_app, MyApp.API, pagination: MyApp.MyPagination

Actual pagination needs to be handled by your application and is outside the scope of this library.

Links can be generated using the JSONAPIPlug.page information stored in the connection jsonapi_plug private field and by passing additional information to your pagination module by passing options from your controller.

See the tests for an example implementation of page based pagination strategy.

Summary

Types

link()

@type link() :: :first | :last | :next | :prev

links()

@type links() :: %{required(link()) => String.t()}

options()

@type options() :: Keyword.t()

params()

@type params() :: %{required(String.t()) => String.t()}

t()

@type t() :: module()

Callbacks

paginate(arg1, arg2, params, options)

@callback paginate(
  [JSONAPIPlug.Resource.t()] | nil,
  Plug.Conn.t() | nil,
  params(),
  JSONAPIPlug.Resource.options()
) :: links()

Functions

url_for(resources, conn, params)

@spec url_for(
  [JSONAPIPlug.Resource.t()],
  Plug.Conn.t() | nil,
  params() | nil
) :: JSONAPIPlug.Document.LinkObject.t()