View Source ExTypesense.HttpClient (ExTypesense v0.7.3)

Http client for Typesense server.

Summary

Functions

Returns the Typesense's API key

Command for making http requests.

Types

Link to this type

request_body()

View Source (since 0.1.0)
@type request_body() :: iodata() | nil
Link to this type

request_method()

View Source (since 0.1.0)
@type request_method() :: :get | :post | :delete | :patch | :put
Link to this type

request_path()

View Source (since 0.1.0)
@type request_path() :: String.t()

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

Link to this function

get_host()

View Source (since 0.1.0)
@spec get_host() :: String.t() | nil
Link to this function

get_options()

View Source (since 0.7.0)
@spec get_options() :: Keyword.t()
Link to this function

get_port()

View Source (since 0.1.0)
@spec get_port() :: non_neg_integer() | nil
Link to this function

get_scheme()

View Source (since 0.1.0)
@spec get_scheme() :: String.t() | nil
Link to this function

request(conn, opts \\ %{})

View Source (since 0.4.0)
@spec request(ExTypesense.Connection.t(), map()) ::
  {:ok, any()} | {:error, String.t()}

Command for making http requests.

Options

  • :body Payload for passing as request body (defaults to nil).
  • :path Request path.
  • :method Request method (e.g. :get, :post, :put, :patch, :delete). Defaults to :get.
  • :query Request query params (defaults to %{}).
  • :content_type "Content-Type" request header. Defaults to "application/json".

Examples

iex> connection = %ExTypesense.Connection{
...>   host: "localhost",
...>   api_key: "some_api_key",
...>   port: "8108",
...>   scheme: "http"
...> }

iex> HttpClient.request(connection, %{method: :post, path: "/collections", body: ExTypesense.TestSchema.Person})
{:ok,
  [%{
    "created_at" => 123456789,
    "default_sorting_field" => "person_id",
    "fields" => [...],
    "name" => "persons",
    "num_documents" => 0,
    "symbols_to_index" => [],
    "token_separators" => []
  }]
}