View Source Snap.Cluster behaviour (Snap v0.9.0)

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

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

The body of the HTTP request

@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()}
]

Options available for configuring the Cluster

An error from an HTTP operation

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

Any additional HTTP headers sent with the request

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

Options passed through to the request

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

The query params, which will be appended to the path

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

The path of the HTTP endpoint

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

The result from an HTTP operation

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

A successful results from an HTTP operation

Callbacks

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

Returns the config in use by this cluster.

Link to this callback

delete(path, params, headers, opts)

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

Sends a DELETE request.

Returns either:

Link to this callback

get(path, params, headers, opts)

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

Sends a GET request.

Returns either:

@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.

Link to this callback

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

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

Sends a POST request.

Returns either:

Link to this callback

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

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

Sends a PUT request.

Returns either: