livery_client_adapter behaviour (livery v0.4.3)
View SourceBehaviour for an outbound HTTP transport, the client-side dual of
livery_adapter.
An adapter owns the wire: it takes a livery_client:request() and
produces a livery_client:response() (or an error). The composable
layers (timeout, retry, concurrency, circuit breaker) sit above it and
do not care which transport runs underneath. The default adapter is
livery_client_hackney (HTTP/1.1, HTTP/2, and HTTP/3 via hackney);
write your own to front a different client.
Callbacks
request(Request, Opts) -> {ok, Response} | {error, term()}- send one request. The adapter owns its connections and pooling.read(Reader, Timeout) -> {ok, Data, Reader} | {done, Reader} | {error, term()}- optional; pull the next chunk of a streamed response body. Only adapters that return a{stream, Reader}response body implement it.stream(Request, Opts, StreamOpts) -> {ok, Ref} | {error, term()}- optional; drive the request in a background process owned by the adapter and deliver the response toStreamOpts'sstream_topid as ordered{livery_response, Ref, _}messages ({status, Status, Headers},{chunk, Binary},done,{error, Reason}).StreamOptscarriesstream_to(the recipient) andflow(autoto push as fast as the wire allows,manualto send one chunk perstream_next/1).Refis opaque and identifies the stream forstream_next/1andstop_stream/1.stream_next(Ref) -> ok | {error, term()}- optional; underflow => manual, ask for one more body chunk.stop_stream(Ref) -> ok- optional; cancel a push stream and release its connection.
Summary
Types
Callbacks
-callback request(livery_client:request(), map()) -> {ok, livery_client:response()} | {error, term()}.
-callback stop_stream(stream_ref()) -> ok.
-callback stream(livery_client:request(), map(), stream_opts()) -> {ok, stream_ref()} | {error, term()}.
-callback stream_next(stream_ref()) -> ok | {error, term()}.