Dowser. Client
(Dowser.Client v0.3.0)
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
over Dowser.Client.HTTP (OTP's :httpc), and decodes the response body
according to :format, returning {:ok, %Dowser.Client.Response{}} or
{:error, exception}.
All option resolution — header merging, URL/query building and body encoding —
happens in Dowser.Client.Request.new/5 before the transport is called;
response decoding follows the same :format.
Errors
Errors are always Dowser exceptions, never a dependency's own exception type:
Dowser.Client.Error— context resolution, invalid:auth/:format/:keys/:decoder/:encoder/:encode/:retry, or a:keys,:decoderor:encoderfunction that raised.Dowser.Client.JSON.Error— body encoding or decoding failure.Dowser.Client.HTTP.Error— transport failure.
Options
Every option below can be set globally (config :dowser_client, ...), per
context (Dowser.Client.Context), or per request — most specific wins, except
:http_opts, which merges across all three (most specific wins per key).
:context— the search backend to query (seeDowser.Client.Context); absent resolves the:defaultentry fromconfig :dowser_client, contexts: [...](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.:keys—:strings(default),:atoms,:atoms!, or a(String.t() -> term)function; how a decoded response body's keys are cast.:decoder— a module exportingdecode/2, a(body, opts -> term)function, or either paired with the options it needs ({MyDecoder, mapping: mapping}), owning the decoded response body. It receives its own options plus:key_fnand:context, and does the backend-specific castingdowser_clientcan't: finding documents in the envelope, resolving each one's mapping, casting its fields.:encoder— a module exportingencode/2, a(source, opts -> term)function, or either paired with the options it needs ({MyEncoder, index: "articles"}), casting a document source in a request body against the mapping of the index it is going to. A query is never encoded.:encode— where that source is in this request's body:false(default),true(the body is the source), a path (["doc"]for an update), or a list of paths. Per request only — the call site is the only place that knows. SeeDowser.Client.Encoder.:keysand:decoderdrive one optional second pass over the decoded body; with neither set there is no second pass and the body stays the plain, string-keyed termDowser.Client.JSON/Dowser.Client.NDJSONproduced. SeeDowser.Client.Decoder.:http_opts— transport options forwarded toDowser.Client.HTTP.request/5—:connect_timeout,:timeout,:ssl,:profile,:profile_opts, ... — including:headers(a map or list of{name, value}pairs, merged over global and context headers plus a derivedcontent-type).:ssland:profile_optsmerge per key across the three tiers; seeDowser.Client.HTTP.:retry— retry policy for transient failures; seeDowser.Client.Retry.
Summary
Types
@type method() :: Dowser.Client.HTTP.method()
@type result() :: {:ok, Dowser.Client.Response.t()} | {:error, Exception.t()}
Functions
Runs a DELETE; see request/4.
Runs a GET; see request/4.
Runs a PATCH; see request/4.
Runs a POST; see request/4.
Runs a PUT; see request/4.
Runs an HTTP request against the context given in opts[:context].
Returns {:ok, %Dowser.Client.Response{}} on a completed exchange (any HTTP
status), or {:error, exception} when the context cannot be resolved, the
body cannot be encoded/decoded, or the transport fails.