View Source JSONAPIPlug.Normalizer behaviour (jsonapi_plug v1.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.
Link to this section Summary
Link to this section Types
Link to this section Callbacks
@callback denormalize_attribute( params(), JSONAPIPlug.Resource.field_name(), term() ) :: params() | no_return()
@callback denormalize_relationship( params(), JSONAPIPlug.Document.RelationshipObject.t() | [JSONAPIPlug.Document.RelationshipObject.t()], JSONAPIPlug.Resource.field_name(), term() ) :: params() | no_return()
@callback normalize_attribute(params(), JSONAPIPlug.Resource.field_name()) :: value() | no_return()
Link to this section 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( JSONAPIPlug.Resource.t(), Plug.Conn.t() | nil, JSONAPIPlug.Resource.data() | nil, JSONAPIPlug.Resource.meta() | nil, JSONAPIPlug.Resource.options() ) :: JSONAPIPlug.Document.t() | no_return()
Transforms user data into a JSON:API Document