Conduit v0.12.10 Conduit.ContentType behaviour View Source

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.

Link to this section Summary

Functions

Formats the message body with the specified content type

Parses the message body with the specified content type

Link to this section Functions

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
"{}"

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
%{}

Link to this section Callbacks