View Source ExTypesense.HttpClient (ExTypesense v0.4.1)

Http client for Typesense server.

Summary

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

Link to this function

get_host()

View Source (since 0.1.0)
Link to this function

get_port()

View Source (since 0.1.0)
Link to this function

get_scheme()

View Source (since 0.1.0)
Link to this function

httpc_run(uri, method, payload, content_type \\ ~c"application/json")

View Source (since 0.3.0)
This function is deprecated. Use request/2 instead.
@spec httpc_run(URI.__struct__(), atom(), String.t(), list()) ::
  {:ok, map()} | {:error, map()}
Link to this function

request(conn, opts \\ %{})

View Source (since 0.4.0)
@spec request(ExTypesense.Connection.t(), map()) :: nil

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" => []
  }]
}
Link to this function

run(request_method, request_path, body \\ nil, query \\ %{})

View Source (since 0.1.0)
This function is deprecated. Use request/2 instead.
@spec run(request_method(), request_path(), request_body(), map()) ::
  {:ok, map()} | {:error, map()}

Req client.

Examples

iex> HttpClient.run(:get, "/collections")
{:ok,
  [%{
    "created_at" => 123456789,
    "default_sorting_field" => "num_employees",
    "fields" => [...],
    "name" => "companies",
    "num_documents" => 0,
    "symbols_to_index" => [],
    "token_separators" => []
  }]
}