livery_client (livery v0.2.0)
View SourceA composable HTTP client: the outbound twin of the server middleware.
Build a client once with new/1 (a transport adapter, a base URL,
default headers, and a layer stack), then call it with get/2, post/3,
request/3,4. Layers run outermost-first and each is
call(Request, Next, State) -> {ok, response()} | {error, term()}, the
same shape as server middleware, with errors threaded as values.
Client = livery_client:new(#{
base_url => <<"https://api.example.com">>,
stack => [
livery_client:timeout(5000),
livery_client:retry(#{max => 3}),
livery_client:circuit_breaker(#{name => api}),
livery_client:concurrency(50)
]
}),
{ok, Resp} = livery_client:get(Client, <<"/users/42">>),
200 = livery_client:status(Resp).The transport is a livery_client_adapter; the default,
livery_client_hackney, speaks HTTP/1.1, HTTP/2, and HTTP/3.
Summary
Functions
Add an endpoint to a balance pool at runtime.
Spread requests across a pool of endpoints, with passive outlier
ejection and lazy half-open recovery. Opts: name (required),
endpoints (base URLs or a {Module, Arg} discovery pair), policy
(p2c | round_robin), eject_after, eject_for, fail_status.
With balance you pass paths; the chosen endpoint supplies the host.
Build a client. Opts: adapter (default livery_client_hackney),
adapter_opts, base_url, headers (defaults applied to every
request), stack (the layers).
Pull the next chunk of a {stream, Reader} response body.
Drain a {stream, Reader} response body to a single binary.
Point a request URL at a chosen endpoint. Strips any scheme+authority
the URL already carries and joins the endpoint with the remaining
path+query, so the balancer owns the host. Used by livery_client_balance.
Remove an endpoint from a balance pool at runtime.
Send a request. Opts: body (iodata | {full, _} | {stream, Fun}),
headers, timeout, stream (true to receive a {stream, Reader}
response body), meta.
Run a fully built request through the client's layer stack.
Types
Functions
Add an endpoint to a balance pool at runtime.
Spread requests across a pool of endpoints, with passive outlier
ejection and lazy half-open recovery. Opts: name (required),
endpoints (base URLs or a {Module, Arg} discovery pair), policy
(p2c | round_robin), eject_after, eject_for, fail_status.
With balance you pass paths; the chosen endpoint supplies the host.
-spec concurrency(non_neg_integer()) -> entry().
Build a client. Opts: adapter (default livery_client_hackney),
adapter_opts, base_url, headers (defaults applied to every
request), stack (the layers).
Pull the next chunk of a {stream, Reader} response body.
Drain a {stream, Reader} response body to a single binary.
Point a request URL at a chosen endpoint. Strips any scheme+authority
the URL already carries and joins the endpoint with the remaining
path+query, so the balancer owns the host. Used by livery_client_balance.
Remove an endpoint from a balance pool at runtime.
Send a request. Opts: body (iodata | {full, _} | {stream, Fun}),
headers, timeout, stream (true to receive a {stream, Reader}
response body), meta.
Run a fully built request through the client's layer stack.
-spec status(response()) -> 100..599.
-spec timeout(pos_integer()) -> entry().