View Source JSONAPIPlug.Normalizer behaviour (jsonapi_plug v2.0.0)

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

The default implementation transforms JSON:APIdocuments 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.

defmodule MyApp.API.Normalizer
  ...

  @behaviour JSONAPIPlug.Normalizer

  ...
end

and by configuring it in your api configuration:

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.

Summary

Functions

Transforms a JSON:API Document user data

Transforms user data into a JSON:API Document

Types

Callbacks

Link to this callback

denormalize_attribute(params, field_name, term)

View Source
@callback denormalize_attribute(
  params(),
  JSONAPIPlug.Resource.field_name(),
  term()
) :: params() | no_return()
Link to this callback

denormalize_relationship(params, t, field_name, term)

View Source
@callback denormalize_relationship(
  params(),
  JSONAPIPlug.Document.RelationshipObject.t(),
  JSONAPIPlug.Resource.field_name(),
  term()
) :: params() | no_return()
@callback resource_params() :: params() | no_return()

Functions

Link to this function

denormalize(document, resource, conn)

View Source

Transforms a JSON:API Document user data

Link to this function

normalize(conn, resource_or_resources, links, meta, options)

View Source

Transforms user data into a JSON:API Document