Dowser.Client.JSON.Adapter behaviour (Dowser.Client v0.1.1)

View Source

Behaviour implemented by every JSON codec.

Adapters convert between Elixir terms and JSON. encode/2 returns iodata (cheap to feed straight into a request body); decode/2 takes the raw response binary. Both accept a keyword list of codec-specific options and return a tagged tuple instead of raising, so the caller decides how to handle failures.

Decoding yields string-keyed maps unless the underlying codec is told otherwise through opts.

Bundled implementations:

Summary

Types

opts()

@type opts() :: keyword()

Callbacks

decode(binary, opts)

@callback decode(binary(), opts()) :: {:ok, term()} | {:error, term()}

encode(term, opts)

@callback encode(term(), opts()) :: {:ok, iodata()} | {:error, term()}