tesla v0.10.0 Tesla.Middleware.JSON View Source
Encode requests and decode responses as JSON.
This middleware requires poison (or other engine) as dependency.
Remember to add {:poison, ">= 1.0"}
to dependencies (and :poison
to applications in mix.exs
)
Also, you need to recompile tesla after adding :poison
dependency:
mix deps.clean tesla
mix deps.compile tesla
Example usage
defmodule MyClient do
use Tesla
plug Tesla.Middleware.JSON # use poison engine
# or
plug Tesla.Middleware.JSON, engine: JSX, engine_opts: [strict: [:comments]]
# or
plug Tesla.Middleware.JSON, decode: &JSX.decode/1, encode: &JSX.encode/1
end
Options
Link to this section Summary
Functions
Callback implementation for Tesla.Middleware.call/3
Decode response body as JSON. Used by Tesla.Middleware.DecodeJson
Encode request body as JSON. Used by Tesla.Middleware.EncodeJson
Link to this section Functions
Callback implementation for Tesla.Middleware.call/3
.
Decode response body as JSON. Used by Tesla.Middleware.DecodeJson
Encode request body as JSON. Used by Tesla.Middleware.EncodeJson