accent v1.1.1 Accent.Plug.Response
Transforms the keys of an HTTP response to the case requested by the client.
A client can request what case the keys are formatted in by passing the case
as a header in the request. By default the header key is Accent
. If the
client does not request a case or requests an unsupported case then a default
case defined by :default_case
will be used. If no default case is provided
then no conversion will happen. By default the supported cases are camel
,
pascal
and snake
.
Options
:default_case
- module used to case the response when the client does not request a case or requests an unsupported case. When not provided then no conversation will happen for the above scenarios. Defaults tonil
.:header
- the HTTP header used to determine the case to convert the response body to before sending the response (default:Accent
):json_codec
- module used to encode and decode JSON. The module is expected to definedecode/1
andencode!/1
functions (required).:supported_cases
- map that defines what cases a client can request. By defaultcamel
,pascal
andsnake
are supported.
Examples
plug Accent.Plug.Response, default_case: Accent.Case.Snake,
header: "x-accent",
supported_cases: %{"pascal" => Accent.Case.Pascal},
json_codec: Jason