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:
Placid.Response.Rendering.Engines.JSON
Placid.Response.Rendering.Engines.XML
Summary
serialize_to_body(conn, data, accept) | Serializes |
Functions
Serializes data
when an available rendering engine exists for the given
content_type
.
Arguments
conn
-Plug.Conn
- the current connectiondata
-List
|Map
|Struct
- Elixir terms to be serializedcontent_type
-String
- response content-type
Returns
Plug.Conn