Conduit v0.12.10 Conduit.Plug.Format View Source
Formats the message body based on the content type.
It uses in order of preference:
- The content type specified for the plug.
- The content type specified on the message.
- The default content type
text/plain
.
The location of the content type can be changed from content_type
to a header with the :header
option.
This plug should be used in an outgoing pipeline.
Examples
plug Conduit.Plug.Format
plug Conduit.Plug.Format, content_type: "application/json"
plug Conduit.Plug.Format, header: "Content-Type"
iex> import Conduit.Message
iex> message =
iex> %Conduit.Message{}
iex> |> put_body(%{})
iex> |> Conduit.Plug.Format.run(content_type: "application/json")
iex> message.body
"{}"
iex> message.content_type
"application/json"
iex> import Conduit.Message
iex> message =
iex> %Conduit.Message{}
iex> |> put_body(%{})
iex> |> Conduit.Plug.Format.run(content_type: "application/json", header: "content_type")
iex> message.body
"{}"
iex> get_header(message, "content_type")
"application/json"
Link to this section Summary
Functions
Formats the message body based on the content type
Callback implementation for Conduit.Plug.init/1
Callback implementation for Conduit.Plug.run/2
Link to this section Functions
Formats the message body based on the content type.
Callback implementation for Conduit.Plug.init/1
.
Callback implementation for Conduit.Plug.run/2
.