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: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.
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
Types
Callbacks
@callback denormalize_attribute( params(), JSONAPIPlug.Resource.field_name(), term() ) :: params() | no_return()
@callback denormalize_relationship( params(), JSONAPIPlug.Document.RelationshipObject.t(), JSONAPIPlug.Resource.field_name(), term() ) :: params() | no_return()
Functions
@spec denormalize(JSONAPIPlug.Document.t(), JSONAPIPlug.Resource.t(), Plug.Conn.t()) :: Plug.Conn.params() | no_return()
Transforms a JSON:API Document user data
@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