OpenApiTypesense.Client behaviour (OpenApiTypesense v0.6.5)
View SourceHttp 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
@type response() :: {:ok, any()} | {:error, OpenApiTypesense.ApiResponse.t()} | {:error, String.t()} | {:error, list()} | :error
Callbacks
Functions
@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).
This function is deprecated. Use OpenApiTypesense.Connection.config(:client) instead.
@spec get_client() :: keyword() | nil
This function is deprecated. Use OpenApiTypesense.Connection.config(:host) instead.
@spec get_host() :: String.t() | nil
This function is deprecated. Use OpenApiTypesense.Connection.config(:port) instead.
@spec get_port() :: non_neg_integer() | nil
This function is deprecated. Use OpenApiTypesense.Connection.config(:scheme) instead.
@spec get_scheme() :: String.t() | nil
@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 tonil
).: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}}