diff --git a/lib/supabase/fetcher.ex b/lib/supabase/fetcher.ex index 8b51770..4426256 100644 --- a/lib/supabase/fetcher.ex +++ b/lib/supabase/fetcher.ex @@ -36,7 +36,7 @@ defmodule Supabase.Fetcher do when url: String.t() | URI.t(), body: binary | nil | {:stream, Enumerable.t()}, headers: list(tuple) - defp new_connection(method, url, body, headers) do + def new_connection(method, url, body, headers) do headers = merge_headers(default_headers(), headers) Finch.build(method, url, headers, body) end @@ -170,6 +170,34 @@ defmodule Supabase.Fetcher do |> format_response() end + @doc """ + Simple HEAD request that format the response to a map or + retrieve the error as `String.t()` + """ + @impl true + def head(url, body, headers \\ []) do + headers = merge_headers(headers, [{"content-type", "application/json"}]) + + :head + |> new_connection(url, Jason.encode_to_iodata!(body), headers) + |> Finch.request(Supabase.Finch) + |> format_response() + end + + @doc """ + Simple PATCH request that format the response to a map or + retrieve the error as `String.t()` + """ + @impl true + def patch(url, body, headers \\ []) do + headers = merge_headers(headers, [{"content-type", "application/json"}]) + + :put + |> new_connection(url, Jason.encode_to_iodata!(body), headers) + |> Finch.request(Supabase.Finch) + |> format_response() + end + @doc """ Simple DELETE request that format the response to a map or retrieve the error reason as `String.t()`. diff --git a/lib/supabase/fetcher_behaviour.ex b/lib/supabase/fetcher_behaviour.ex index 6c6b4be..a68b3bb 100644 --- a/lib/supabase/fetcher_behaviour.ex +++ b/lib/supabase/fetcher_behaviour.ex @@ -15,6 +15,8 @@ defmodule Supabase.FetcherBehaviour do when opts: [resolve_json: boolean] @callback post(url, body, headers) :: result @callback put(url, body, headers) :: result + @callback head(url, body, headers) :: result + @callback patch(url, body, headers) :: result @callback delete(url, body, headers) :: result @callback upload(method, url, Path.t(), headers) :: result @callback stream(url, headers, keyword) :: {:ok, stream} | {:error, reason}