Snap.Cluster behaviour (Snap v0.13.0)

View Source

Defines a cluster.

A cluster maps to an Elasticsearch endpoint.

When used, the cluster expects :otp_app as an option. The :otp_app should point to an OTP application that has the cluster configuration. For example, this cluster:

defmodule MyApp.Cluster do
  use Snap.Cluster, otp_app: :my_app
end

Can be configured with:

config :my_app, MyApp.Cluster,
  url: "http://localhost:9200",
  username: "username",
  password: "password",
  index_namespace: "app-dev"

For details about how index namespacing works, see Snap.Cluster.Namespace.

Summary

Types

The body of the HTTP request

Options available for configuring the Cluster

An error from an HTTP operation

Any additional HTTP headers sent with the request

Options passed through to the request

The query params, which will be appended to the path

The path of the HTTP endpoint

The result from an HTTP operation

A successful results from an HTTP operation

Callbacks

Returns the config in use by this cluster.

Sends a DELETE request.

Sends a GET request.

Sets up the config for the cluster.

Types

body()

@type body() :: String.t() | nil | binary() | map()

The body of the HTTP request

config_opts()

@type config_opts() :: [
  url: String.t(),
  username: String.t(),
  password: String.t(),
  auth: Snap.Auth.t(),
  index_namespace: String.t() | nil,
  telemetry_prefix: [atom()],
  http_client_adapter:
    Snap.HTTPClient.t() | {Snap.HTTPClient.t(), adapter_config :: Keyword.t()},
  json_library: module()
]

Options available for configuring the Cluster

error()

An error from an HTTP operation

headers()

@type headers() :: Snap.HTTPClient.headers()

Any additional HTTP headers sent with the request

opts()

@type opts() :: Keyword.t()

Options passed through to the request

params()

@type params() :: Keyword.t()

The query params, which will be appended to the path

path()

@type path() :: String.t()

The path of the HTTP endpoint

result()

@type result() :: success() | error()

The result from an HTTP operation

success()

@type success() :: {:ok, map()}

A successful results from an HTTP operation

Callbacks

config()

@callback config() :: Keyword.t()

Returns the config in use by this cluster.

delete(path, params, headers, opts)

@callback delete(path(), params(), headers(), opts()) :: result()

Sends a DELETE request.

Returns either:

get(path, params, headers, opts)

@callback get(path(), params(), headers(), opts()) :: result()

Sends a GET request.

Returns either:

init(arg1)

@callback init(Keyword.t() | nil) :: {:ok, Keyword.t()}

Sets up the config for the cluster.

Override this to dynamically load a config from somewhere other than your application config.

post(path, body, params, headers, opts)

@callback post(path(), body(), params(), headers(), opts()) :: result()

Sends a POST request.

Returns either:

put(path, body, params, headers, opts)

@callback put(path(), body(), params(), headers(), opts()) :: result()

Sends a PUT request.

Returns either: