TeslaCase.Middleware (tesla_case v0.1.0)

Tesla middleware for converting the body keys of the request and response. This middleware will convert all keys from the body of the request using the appropriate function before performing it and will convert all keys from the body of the response to snake case.

Examples

defmodule MyClient do
  use Tesla
  plug TeslaCase.Middleware # use defaults
  # or
  plug TeslaCase.Middleware, encode: &Recase.to_camel/1, serializer: &Recase.Enumerable.stringify_keys/2
end

Options

  • :serializer - serializer function with arity 2, receives the data as the first parameter and the :encode as the second parameter, (defaults to &Recase.Enumerable.stringify_keys/2)
  • :encode - encoding function, e.g &Recase.to_camel/1, &Recase.to_pascal/1 (defaults to &Recase.to_camel/1)