Conduit v0.1.1 Conduit.ContentType behaviour

Formats and parses a message body based on the content type given.

Custom content types can be specified in your configuration.

config :conduit, Conduit.ContentType, [{"application/x-custom", MyApp.CustomContentType}]

Note that any new content types specified in this way will require a recompile of Conduit.

$ mix deps.clean conduit --build
$ mix deps.get

Any custom content types should implement the Conduit.ContentType behaviour. See Conduit.ContentType.JSON for an example.

Summary

Functions

Formats the message body with the specified content type

Parses the message body with the specified content type

Functions

format(message, type, opts)

Formats the message body with the specified content type.

Examples

iex> import Conduit.Message
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_body(%{})
iex>   |> Conduit.ContentType.format("application/json", [])
iex> message.body
"{}"
iex> get_meta(message, :content_type)
"application/json"
parse(message, type, opts)

Parses the message body with the specified content type.

Examples

iex> import Conduit.Message
iex> message =
iex>   %Conduit.Message{}
iex>   |> put_body("{}")
iex>   |> Conduit.ContentType.parse("application/json", [])
iex> message.body
%{}
iex> get_meta(message, :content_type)
"application/json"

Callbacks

format(arg0, arg1)
parse(arg0, arg1)