JSONAPI.Serializer (jsonapi v1.9.0)

View Source

Serialize a map of data into a properly formatted JSON API response object

Summary

Types

document()

@type document() :: map()

Functions

build_relationships(conn, parent_info, rel_config, acc, options)

@spec build_relationships(Plug.Conn.t(), tuple(), tuple(), tuple(), list()) :: tuple()

build_relationships(conn, arg, relationship_name, rel_data, rel_view, acc, options)

@spec build_relationships(
  Plug.Conn.t(),
  tuple(),
  term(),
  term(),
  module(),
  tuple(),
  list()
) :: tuple()

data_loaded?(rel_data)

@spec data_loaded?(map() | list()) :: boolean()

encode_data(view, data, conn, query_includes, options)

encode_rel_data(view, data)

@spec encode_rel_data(module(), map() | list()) :: map() | nil

encode_relation(info)

@spec encode_relation(tuple()) :: map()

encode_relationships(conn, doc, view_info, options)

@spec encode_relationships(Plug.Conn.t(), document(), tuple(), list()) :: tuple()

extrapolate_relationship_config(arg)

@spec extrapolate_relationship_config(tuple()) ::
  {atom(), atom(), module(), boolean()}

Given the relationship config entry provided by a JSONAPI.View, produce the extrapolated config tuple containing:

  • The name of the relationship to be used when serializing
  • The key in the data the relationship is found under
  • The relationship resource's JSONAPI.View module
  • A boolean for whether the relationship is included by default or not

flatten_included(included)

@spec flatten_included(keyword()) :: keyword()

serialize(view, data, conn \\ nil, meta \\ nil, options \\ [])

Takes a view, data and a optional plug connection and returns a fully JSONAPI Serialized document. This assumes you are using the JSONAPI.View and have data in maps or structs.

Please refer to JSONAPI.View for more information. If you are in interested in relationships and includes you may also want to reference the JSONAPI.QueryParser.