Tesla.Middleware.Mold
Tesla middleware that validates response status codes and parses response bodies against Mold schemas declared at the call site.
Tesla.get(client, "/users/#{id}", opts: [mold: %{200 => user_schema(), 404 => nil}])
A 200 with the declared shape is accepted, 404 is accepted without parsing
the body, anything else fails the request. Because the check runs inside the
Tesla middleware chain, unexpected statuses and schema mismatches become failed
requests in Tesla's telemetry events, not silent problems surfacing later.
Installation
def deps do
[
{:tesla_middleware_mold, "~> 0.1"}
]
endDocumentation
Full docs at hexdocs.pm/tesla_middleware_mold. The Mold pattern guide explains the reasoning behind the approach.
License
Apache-2.0