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

Transforms user data to and from a `JSON:API` Document.

The default implementation transforms `JSON:API`documents in requests to an ecto
friendly format and expects `Ecto.Schema` instances when rendering data in responses.
The data it produces is stored under the `:params` key of the `JSONAPIPlug` struct
that will be stored in the `Plug.Conn` private assign `:jsonapi_plug`.

You can customize normalization to convert your application data to and from
the `JSONAPIPlug.Document` data structure by providing an implementation of
the `JSONAPIPlug.Normalizer` behaviour.

```elixir
defmodule MyApp.API.Normalizer
  ...

  @behaviour JSONAPIPlug.Normalizer

  ...
end
```

and by configuring it in your api configuration:

```elixir
config :my_app, MyApp.API, normalizer: MyApp.API.Normalizer
```

You can return an error during parsing by raising `JSONAPIPlug.Exceptions.InvalidDocument` at
any point in your normalizer code.

# `params`

```elixir
@type params() :: term()
```

# `t`

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

# `value`

```elixir
@type value() :: term()
```

# `denormalize_attribute`

```elixir
@callback denormalize_attribute(
  params(),
  JSONAPIPlug.Resource.field_name(),
  term()
) :: params() | no_return()
```

# `denormalize_relationship`

```elixir
@callback denormalize_relationship(
  params(),
  JSONAPIPlug.Document.RelationshipObject.t(),
  JSONAPIPlug.Resource.field_name(),
  term()
) :: params() | no_return()
```

# `resource_params`

```elixir
@callback resource_params() :: params() | no_return()
```

# `denormalize`

```elixir
@spec denormalize(JSONAPIPlug.Document.t(), JSONAPIPlug.Resource.t(), Plug.Conn.t()) ::
  Plug.Conn.params() | no_return()
```

Transforms a JSON:API Document user data

# `normalize`

```elixir
@spec normalize(
  Plug.Conn.t(),
  JSONAPIPlug.Resource.t() | [JSONAPIPlug.Resource.t()] | nil,
  JSONAPIPlug.Document.links() | nil,
  JSONAPIPlug.Document.meta() | nil,
  JSONAPIPlug.Resource.options()
) :: JSONAPIPlug.Document.t() | no_return()
```

Transforms user data into a JSON:API Document

---

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