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

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

@type response() :: {:ok, any()} | {:error, any()}
@type response_type() :: String.t()

Functions

Link to this function

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

View Source

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.
Link to this function

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

View Source

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.
@spec default_config() :: any()
Link to this function

flatten(data, prefix \\ "")

View Source

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

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

View Source

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.

Sets the JWT.

Parameters

  • jwt: The JSON Web Token.

Returns

  • Updated Header map.
@spec set_locale(String.t()) :: Appwrite.Types.Client.Headers.t()
@spec set_locale(String.t()) :: Appwrite.Types.Client.Headers.t()

Sets the locale.

Parameters

  • client: The current client instance.
  • locale: The locale string.

Returns

  • Updated client instance.
@spec set_project(String.t()) :: Appwrite.Types.Client.Config.t()

Sets the Project.

Parameters

  • project: The Project Name.

Returns

  • Updated Config map.
@spec set_session(String.t()) :: Appwrite.Types.Client.Headers.t()

Sets the session.

Parameters

  • client: The current client instance.
  • session: The session string.

Returns

  • Updated client instance.