View Source Appwrite.Utils.Client (appwrite v0.1.9)

Client module for handling requests to Appwrite.

Summary

Functions

Makes an HTTP call using the given method, URL, headers, and parameters.

Flattens a nested map or list into a single-level map with prefixed keys.

Prepares an HTTP request with the specified method, URL, headers, and parameters.

Sets the JWT.

Sets the locale.

Sets the Project.

Sets the session.

Types

response()

@type response() :: {:ok, any()} | {:error, any()}

response_type()

@type response_type() :: String.t()

Functions

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

Makes an HTTP call using the given method, URL, headers, and parameters.

Parameters

  • method: HTTP method.
  • url: Target URL.
  • headers: Map of headers.
  • params: Parameters for the request.
  • response_type: Type of response expected (default: "json").

Returns

  • Response data or raises an AppwriteException on error.

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

Handles chunked uploads for large files.

Parameters

  • method: HTTP method (e.g., "POST").
  • url: Target URL.
  • headers: Map of headers.
  • payload: Original payload with file details.
  • on_progress: Function to call with progress updates.

Returns

  • Response from the final chunk.

flatten(data, prefix \\ "")

Flattens a nested map or list into a single-level map with prefixed keys.

Examples

iex> Client.flatten(%{"key1" => %{"key2" => "value"}}, "prefix")
%{"prefix[key1][key2]" => "value"}

iex> Client.flatten(%{"key1" => ["a", "b"]}, "prefix")
%{"prefix[key1][0]" => "a", "prefix[key1][1]" => "b"}

get_app_name()

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

Prepares an HTTP request with the specified method, URL, headers, and parameters.

Parameters

  • method: HTTP method as a string (e.g., "GET", "POST").
  • url: Base URL as a string.
  • headers: Map of headers (default: %{}).
  • params: Map of query or body parameters (default: %{}).

Returns

  • Tuple containing the URI and options for the request.

set_jwt(jwt)

Sets the JWT.

Parameters

  • jwt: The JSON Web Token.

Returns

  • Updated Header map.

set_locale(locale)

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

Sets the locale.

Parameters

  • locale: The locale string.

Returns

  • Updated client instance.

set_project(project)

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

Sets the Project.

Parameters

  • project: The Project Name.

Returns

  • Updated Config map.

set_session(session)

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

Sets the session.

Parameters

  • session: The session string.

Returns

  • Updated client instance.