Tesla.Middleware.JSON (tesla v1.4.0) View Source
Encode requests and decode responses as JSON.
This middleware requires jason (or other engine) as dependency.
Remember to add {:jason, ">= 1.0"}
to dependencies
Also, you need to recompile tesla after adding :jason
dependency:
mix deps.clean tesla
mix deps.compile tesla
Example usage
defmodule MyClient do
use Tesla
plug Tesla.Middleware.JSON # use jason engine
# or
plug Tesla.Middleware.JSON, engine: JSX, engine_opts: [strict: [:comments]]
# or
plug Tesla.Middleware.JSON, engine: Poison, engine_opts: [keys: :atoms]
# or
plug Tesla.Middleware.JSON, decode: &JSX.decode/1, encode: &JSX.encode/1
end
Options
Link to this section Summary
Link to this section Functions
Decode response body as JSON.
It is used by Tesla.Middleware.DecodeJson
.
Encode request body as JSON.
It is used by Tesla.Middleware.EncodeJson
.