Placid.Response.Rendering

Placid.Response.Rendering provides the ability for a response to be automatically serialized based on its content-type.

Engines

Rendering engines translate Elixir terms into a serialized format. Each engine is responsible for a single type of content and is capable of rendering for multiple mime types.

Rendering engines should implement callbacks for the following behaviour:

defmodule Placid.Response.Rendering.Engine do
  use Behaviour

  @type data    :: Keyword | Map | List
  @type type    :: binary
  @type subtype :: binary

  defcallback serialize(data, type, subtype) :: { :ok, binary } | :next
end

Current, built-in implementations include:

Summary

serialize_to_body(conn, data, accept)

Serializes data when an available rendering engine exists for the given content_type

Functions

serialize_to_body(conn, data, accept)

Serializes data when an available rendering engine exists for the given content_type.

Arguments

  • conn - Plug.Conn - the current connection
  • data - List | Map | Struct - Elixir terms to be serialized
  • content_type - String - response content-type

Returns

Plug.Conn