Arangox v0.5.0 Arangox.Client behaviour View Source

HTTP client behaviour for Arangox. Arangox uses client implementations to perform all it's connection and execution operations.

To use an http library other than :gun or :mint, implement this behaviour in a module and pass that module to the :client start option.

Link to this section Summary

Callbacks

Receives an Arangox.Endpoint struct and all the start options from Arangox.start_link/1.

Receives a Arangox.Request struct and a connection's state (an Arangox.Connection struct), and returns an Arangox.Response struct or error (or exception struct), along with the new state (which doesn't necessarily need to change).

Link to this section Types

Link to this type

exception_or_reason()

View Source
exception_or_reason() :: any()

Link to this section Functions

Link to this function

alive?(state)

View Source
alive?(Arangox.Connection.t()) :: boolean()
Link to this function

close(state)

View Source
close(Arangox.Connection.t()) :: :ok
Link to this function

connect(client, endpoint, start_options)

View Source
connect(module(), Endpoint.t(), [Arangox.start_option()]) ::
  {:ok, socket()} | {:error, exception_or_reason()}
Link to this function

request(request, state)

View Source
request(Arangox.Request.t(), Arangox.Connection.t()) ::
  {:ok, Arangox.Response.t(), Arangox.Connection.t()}
  | {:error, exception_or_reason(), Arangox.Connection.t()}

Link to this section Callbacks

Link to this callback

alive?(state)

View Source
alive?(state :: Arangox.Connection.t()) :: boolean()
Link to this callback

close(state)

View Source
close(state :: Arangox.Connection.t()) :: :ok
Link to this callback

connect(endpoint, start_options)

View Source
connect(endpoint :: Endpoint.t(), start_options :: [Arangox.start_option()]) ::
  {:ok, socket()} | {:error, exception_or_reason()}

Receives an Arangox.Endpoint struct and all the start options from Arangox.start_link/1.

The socket returned from this callback gets placed in the :socket field of an Arango.Connection struct (a connection's state) to be used by the other callbacks as needed. It can be anything, a tuple, another struct, whatever the client needs.

It's up to the client to consolidate the :connect_timeout, :transport_opts and :client_opts options.

Link to this callback

request(request, state)

View Source
request(request :: Arangox.Request.t(), state :: Arangox.Connection.t()) ::
  {:ok, Arangox.Response.t(), Arangox.Connection.t()}
  | {:error, exception_or_reason(), Arangox.Connection.t()}

Receives a Arangox.Request struct and a connection's state (an Arangox.Connection struct), and returns an Arangox.Response struct or error (or exception struct), along with the new state (which doesn't necessarily need to change).

Arangox handles the encoding and decoding of request and response bodies, and merging headers.

If a connection is lost, this may return {:error, :noproc, state} to force a disconnect, otherwise an attempt to reconnect may not be made until the next request hitting this process fails.