View Source OpenApiTypesense.Client (OpenApiTypesense v0.4.1)

Http client for Typesense server.

Summary

Functions

Returns the Typesense's API key

Command for making http requests.

Types

response()

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

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

get_host()

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

get_options()

(since 0.3.0)
@spec get_options() :: map()

get_port()

(since 0.2.0)
@spec get_port() :: non_neg_integer() | nil

get_scheme()

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

request(conn, opts)

(since 0.2.0)
@spec request(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> alias OpenApiTypesense.{Client,Connection}
iex> connection = %Connection{
...>   host: "localhost",
...>   api_key: "some_api_key",
...>   port: "8108",
...>   scheme: "http"
...> }
iex> opts = %{
...>   args: [],
...>   call: {OpenApiTypesense.Health, :health},
...>   url: "/health",
...>   method: :get,
...>   response: [{200, {OpenApiTypesense.HealthStatus, :t}}],
...>   opts: opts
...> }
iex> Client.request(connection, opts)
{:ok, %OpenApiTypesense.HealthStatus{ok: true}}