View Source ExTypesense.HttpClient (ExTypesense v0.4.3)
Http client for Typesense server.
Summary
Types
Functions
@spec api_key() :: String.t() | nil
Returns the Typesense's API key
Warning
Even if
api_key
is hidden inConnection
struct, this function will still return the key and accessible inside shell (assuming bad actors [pun unintended:/
] can get in as well).
@spec get_host() :: String.t() | nil
@spec get_port() :: non_neg_integer() | nil
@spec get_scheme() :: String.t() | nil
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 request(ExTypesense.Connection.t(), map()) :: {:ok, any()} | {:error, String.t()}
Command for making http requests.
Options
:body
Payload for passing as request body (defaults tonil
).: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" => []
}]
}