Dowser. Client. Request
(Dowser.Client v0.1.1)
View Source
A fully-resolved HTTP request, ready to hand to an HTTP adapter.
new/5 turns a Dowser.Client.Config plus a method, path, body and
per-request options into a %Request{}. All option resolution happens here,
so an adapter only ever sees a finished request:
- headers — merge of global (
config :dowser_client, :http_opts, headers: ...), config (auth+ confighttp_opts[:headers]) and per-request (opts[:http_opts][:headers]) headers, plus acontent-typederived from the request format. Later sources win on name clashes. Each source accepts either a map or a list of{name, value}pairs. - url — the config's endpoint joined with the request path and, when
given,
opts[:params]encoded as a query string. An absolute path is used verbatim. - body — cast through
:codec_adapter(see Casting below), then encoded according to the request format (:json,:ndjsonor:raw) using the resolved JSON adapter and:json_opts. - adapter / http_opts — the resolved
:http_adapterand:http_opts(minus:headers, forwarded separately — see above), merged global → config → request. - retry — the resolved retry policy, from
opts[:retry]; seeDowser.Client.Retry.
Formats
The request and response bodies each have a format (:json, :ndjson or
:raw), resolved from the options:
:format— sets both, and is mutually exclusive with:req_format/:resp_format. Defaults to:json.:req_format/:resp_format— set each direction independently; a missing one falls back to:format(so:json).
Casting
Response/request bodies are cast in two independent ways:
:keys—:strings(default),:atomsor:atoms!; how a decoded response body's keys are cast. Falls back to the config's:keys, thenconfig :dowser_client, :keys, then:strings. Resolved into a:key_fnfunction and passed to:codec_adaptervia:codec_opts— the defaultDowser.Client.Codec.Defaultapplies it; a custom:codec_adapteris responsible for applying it itself if it wants the same behavior.:codec_adapter— a module implementingDowser.Client.Codec, falling back to the config's:codec_adapter, thenconfig :dowser_client, :codec_adapter, thenDowser.Client.Codec.Default(dowser_clienthas no backend-specific knowledge of its own beyond that). When set,codec_adapter.decode/2casts the response body in one pass, andcodec_adapter.encode/2casts the request body before JSON encoding.:codec_opts(merged global → config → request) is forwarded to both, alongside:key_fnand:config(the resolvedDowser.Client.Config).
All casting is skipped when the format is :raw or the body is empty.