OpenApiTypesense.Client behaviour (OpenApiTypesense v0.6.5)

View Source

Http client for Typesense server.

Summary

Callbacks

A callback function for custom HTTP client

Functions

Returns the Typesense's API key

get_client() deprecated
get_host() deprecated
get_port() deprecated
get_scheme() deprecated

Command for making http requests.

Types

response()

(since 0.2.0)
@type response() ::
  {:ok, any()}
  | {:error, OpenApiTypesense.ApiResponse.t()}
  | {:error, String.t()}
  | {:error, list()}
  | :error

Callbacks

request(conn, params)

(since 0.2.0)
@callback request(conn :: map(), params :: keyword()) :: response()

A callback function for custom HTTP client

Functions

api_key()

(since 0.2.0)
@spec api_key() :: String.t() | nil

Returns the Typesense's API key

Warning

Even if api_key is hidden in Connection struct, this function will still return the key and accessible inside shell (assuming bad actors [pun unintended :/] can get in as well).

build_req_client(conn, opts)

(since 0.2.0)

get_client()

(since 0.5.0)
This function is deprecated. Use OpenApiTypesense.Connection.config(:client) instead.
@spec get_client() :: keyword() | nil

get_host()

(since 0.2.0)
This function is deprecated. Use OpenApiTypesense.Connection.config(:host) instead.
@spec get_host() :: String.t() | nil

get_port()

(since 0.2.0)
This function is deprecated. Use OpenApiTypesense.Connection.config(:port) instead.
@spec get_port() :: non_neg_integer() | nil

get_scheme()

(since 0.2.0)
This function is deprecated. Use OpenApiTypesense.Connection.config(:scheme) instead.
@spec get_scheme() :: String.t() | nil

request(conn, opts)

(since 0.2.0)
@spec request(map() | OpenApiTypesense.Connection.t(), map()) :: response()

Command for making http requests.

On using this function

Functions e.g. OpenApiTypesense.Health.health don't need to explicitly pass a connection unless you want to use custom connection. See README for more details or OpenApiTypesense.Connection module.

Options

  • :body: Payload for passing as request body (defaults to nil).
  • :url: Request path.
  • :method: Request method (e.g. :get, :post, :put, :patch, :delete). Defaults to :get.
  • :query: Request query params (defaults to %{}).

Examples

iex> connection = %OpenApiTypesense.Connection{
...>   host: "localhost",
...>   api_key: "some_api_key",
...>   port: "8108",
...>   scheme: "http"
...> }
iex> opts = %{
...>   url: "/health",
...>   method: :get
...> }
iex> Client.request(connection, opts)
{:ok, %OpenApiTypesense.HealthStatus{ok: true}}