Dowser. Client
(Dowser.Client v0.1.1)
View Source
Low-level entry point for querying a search backend over HTTP.
request/4 resolves every option into a Dowser.Client.Request, performs it
against the resolved config's HTTP adapter, and decodes the response body
according to :format, returning {:ok, %Dowser.Client.Response{}} or
{:error, exception}.
All option resolution — header merging, URL/query building, adapter selection
and body encoding — happens in Dowser.Client.Request.new/5 before the
adapter is called; response decoding uses the same :format/JSON adapter.
Errors
Errors are always Dowser exceptions, never a dependency's own exception type:
Dowser.Client.Error— config resolution / invalid:format/:keys/:retry.Dowser.Client.JSON.Error— body encoding or decoding failure.Dowser.Client.Codec.Error—:codec_adapterdecode/2/encode/2failure.Dowser.Client.HTTP.Error— transport failure.
Options
Every option below can be set globally (config :dowser_client, ...), per
config (Dowser.Client.Config), or per request — most specific wins, except
the three _opts keyword lists (:codec_opts, :json_opts, :http_opts),
which merge across all three (most specific wins per key).
:config— the config to query (seeDowser.Client.Config); absent resolves the:defaultentry fromconfig :dowser_client, configs: [...](there is no other built-in fallback).:params— query-string parameters appended to the URL.:format—:json(default),:ndjsonor:raw; selects the codec used to encode the request body and decode the response body (:rawleaves both untouched). Mutually exclusive with:req_format/:resp_format.:req_format/:resp_format— set the request and response formats independently; each falls back to:format(so:json) when omitted.:codec_adapter— a module implementingDowser.Client.Codec, used to cast a decoded response body viadecode/2, and a request body viaencode/2, beyond plain JSON. Defaults toDowser.Client.Codec.Default, which only applies:keyscasting below; seeDowser.Client.Codecfor the full contract.:codec_opts— options forwarded to:codec_adapter'sdecode/2/encode/2(e.g. an index mapping); default[].:keys—:strings(default),:atomsor:atoms!; how object keys in the response body are cast. Applied by the default:codec_adapter; a custom one is responsible for applyingopts[:key_fn]itself if it wants the same behavior.:http_adapter/:json_adapter— the HTTP/JSON adapter modules.:json_opts— options forwarded to the JSON adapter'sencode/2/decode/2.:http_opts— options forwarded to the HTTP adapter'srequest/5, including:headers(a map or list of{name, value}pairs, merged over global and config headers plus a derivedcontent-type).:retry— retry policy for transient failures; seeDowser.Client.Retry.
Summary
Functions
Runs an HTTP request against the config given in opts[:config].
Types
@type method() :: Dowser.Client.HTTP.Adapter.method()
@type result() :: {:ok, Dowser.Client.Response.t()} | {:error, Exception.t()}
Functions
Runs an HTTP request against the config given in opts[:config].
Returns {:ok, %Dowser.Client.Response{}} on a completed exchange (any HTTP
status), or {:error, exception} when the config cannot be resolved, the body
cannot be encoded/decoded, or the transport fails.