Appwrite.Utils.Client (appwrite v1.0.0)

View Source

HTTP client for the Appwrite SDK.

Handles request preparation, authentication headers, chunked file uploads, and response normalisation for all Appwrite service calls.

Summary

Functions

Makes a synchronous HTTP call and returns the decoded response.

Uploads a file, splitting into 5 MB chunks when the file exceeds the limit.

Returns the resolved runtime configuration map.

Flattens a nested map or list into a single-level map with bracket-notation keys, suitable for URI.encode_query/1.

Builds the final URI string and HTTPoison options map for a request.

Returns headers with the JWT token set.

Returns headers with the locale set.

Updates the project ID in the configuration.

Returns headers with the session token set.

Functions

call(method, api_path, headers \\ %{}, params \\ %{}, response_type \\ "json")

Makes a synchronous HTTP call and returns the decoded response.

Raises AppwriteException on network or server errors.

Parameters

  • method — HTTP verb (e.g. "get", "POST").
  • api_path — Path relative to the configured endpoint.
  • headers — Extra headers merged on top of defaults.
  • params — Query params (GET) or body params (other methods).
  • response_type"json" (default), "arrayBuffer", or other.

chunked_upload(method, url, headers \\ %{}, payload \\ %{}, on_progress \\ nil)

Uploads a file, splitting into 5 MB chunks when the file exceeds the limit.

The payload["file"] value must be a map with:

  • "data" — base64-encoded binary
  • "name" — filename string
  • "type" — MIME type string
  • "size" — byte length integer

default_config()

@spec default_config() :: Appwrite.Types.Client.Config.t()

Returns the resolved runtime configuration map.

flatten(data, prefix \\ "")

@spec flatten(map() | list() | any(), String.t()) :: map()

Flattens a nested map or list into a single-level map with bracket-notation keys, suitable for URI.encode_query/1.

Examples

iex> Appwrite.Utils.Client.flatten(%{"a" => %{"b" => "v"}})
%{"a[b]" => "v"}

iex> Appwrite.Utils.Client.flatten(%{"list" => ["x", "y"]})
%{"list[0]" => "x", "list[1]" => "y"}

prepare_request(method, api_path, headers \\ %{}, params \\ %{})

Builds the final URI string and HTTPoison options map for a request.

For GET requests all params are encoded into the query string. For other methods the body is JSON- or multipart-encoded depending on the content-type header.

set_jwt(jwt)

Returns headers with the JWT token set.

set_locale(locale)

@spec set_locale(String.t()) :: Appwrite.Types.Client.Headers.t()

Returns headers with the locale set.

set_project(project)

@spec set_project(String.t()) :: Appwrite.Types.Client.Config.t()

Updates the project ID in the configuration.

set_session(session)

@spec set_session(String.t()) :: Appwrite.Types.Client.Headers.t()

Returns headers with the session token set.