View Source Appwrite.Consts.ExecutionMethod (appwrite v0.1.3)

Provides constants and validation functions for different HTTP methods.

This module defines the allowed HTTP methods (GET, POST, PUT, PATCH, DELETE, OPTIONS) and provides helper functions to validate them, ensuring only recognized methods are used within the application.

Summary

Functions

Returns true if the given method is a valid HTTP method, otherwise false.

Guard clause to check if a given HTTP method is valid.

Validates the given method and returns {:ok, method} if it is valid, or {:error, "Invalid HTTP method"} otherwise.

Validates the given method and returns it if it is valid. Raises an ArgumentError if the method is invalid.

Functions

Link to this function

is_valid_method?(method)

View Source
@spec is_valid_method?(String.t()) :: boolean()

Returns true if the given method is a valid HTTP method, otherwise false.

Examples

iex> ExecutionMethod.is_valid_method?("PUT")
true

iex> ExecutionMethod.is_valid_method?("UNKNOWN")
false
Link to this macro

valid_method(method)

View Source (macro)
@spec valid_method(String.t()) :: boolean()

Guard clause to check if a given HTTP method is valid.

Examples

iex> ExecutionMethod.valid_method("GET")
true

iex> ExecutionMethod.valid_method("UNKNOWN")
false
@spec validate_method(String.t()) :: {:ok, String.t()} | {:error, String.t()}

Validates the given method and returns {:ok, method} if it is valid, or {:error, "Invalid HTTP method"} otherwise.

Examples

iex> ExecutionMethod.validate_method("POST")
{:ok, "POST"}

iex> ExecutionMethod.validate_method("UNKNOWN")
{:error, "Invalid HTTP method"}
Link to this function

validate_method!(method)

View Source
@spec validate_method!(String.t()) :: String.t()

Validates the given method and returns it if it is valid. Raises an ArgumentError if the method is invalid.

Examples

iex> ExecutionMethod.validate_method!("PATCH")
"PATCH"

iex> ExecutionMethod.validate_method!("UNKNOWN")
** (ArgumentError) Invalid HTTP method: "UNKNOWN"