View Source Tesla.Middleware.JSON (tesla v1.7.0)
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
examples
Examples
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
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
.