# `JSONAPIPlug.Pagination`
[🔗](https://github.com/lucacorti/jsonapi_plug/blob/main/lib/jsonapi_plug/pagination.ex#L1)

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:

```elixir
defmodule MyApp.MyController do
  plug JSONAPIPlug.Plug, api: MyApp.MyApi, resource: MyApp.MyResource
end
```

```elixir
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.

# `link`

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

# `links`

```elixir
@type links() :: %{required(link()) =&gt; String.t()}
```

# `options`

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

# `params`

```elixir
@type params() :: %{required(String.t()) =&gt; String.t()}
```

# `t`

```elixir
@type t() :: module()
```

# `paginate`

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

# `url_for`

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

---

*Consult [api-reference.md](api-reference.md) for complete listing*
