Supabase.Fetcher (supabase_potion v0.5.1)
A fundamental HTTP client for interfacing directly with Supabase services.
Supabase.Fetcher
provides the groundwork for sending HTTP requests to the Supabase infrastructure. This includes utilities for various HTTP methods such as GET, POST, PUT, DELETE, and functions to simplify the process of streaming data or uploading files.
Key Features
- Low-level HTTP Interactions: This module allows for raw HTTP requests to any URL, simplifying interactions with web resources.
- Data Streaming: Efficiently stream large data payloads, such as downloading files.
- Request Customization: Extensive header customization and utility functions for constructing requests tailored to your requirements.
- Response Parsing: Automatically converts JSON responses into Elixir maps and handles various response scenarios.
Recommended Usage
While Supabase.Fetcher
is versatile and comprehensive, it operates at a very granular level. For most applications and needs, leveraging higher-level APIs that correspond to specific Supabase services is advisable:
Supabase.Storage
- API to interact directly with buckets and objects in Supabase Storage.
Disclaimer
If your aim is to directly harness this module as a low-level HTTP client, due to missing features in other packages or a desire to craft a unique Supabase integration, you can certainly do so. However, always keep in mind that Supabase.Storage
and other Supabase-oriented packages might offer better abstractions and ease-of-use.
Use Supabase.Fetcher
with a clear understanding of its features and operations.
Summary
Functions
Convenience function that given a apikey
and a optional token
, it will return the headers
to be used in a request to your Supabase API.
Simple DELETE request that format the response to a map or retrieve
the error reason as String.t()
.
Simple GET request that format the response to a map or retrieve
the error reason as String.t()
.
Simple HEAD request that format the response to a map or
retrieve the error as String.t()
Simple PATCH request that format the response to a map or
retrieve the error as String.t()
Simple POST request that format the response to a map or retrieve
the error reason as String.t()
.
Simple PUT request that format the response to a map or retrieve
the error reason as String.t()
.
Makes a HTTP request to the desired URL, with default headers and stream back the response. Good to stream large files downlaods.
Upload a binary to the desired URL.
Functions
apply_client_headers(client, token \\ nil, headers \\ [])
apply_headers(api_key, token \\ nil, headers \\ [])
Convenience function that given a apikey
and a optional token
, it will return the headers
to be used in a request to your Supabase API.
Examples
iex> Supabase.Fetcher.apply_conn_headers("apikey-value")
[{"apikey", "apikey-value"}, {"authorization", "Bearer apikey-value"}]
iex> Supabase.Fetcher.apply_conn_headers("apikey-value", "token-value")
[{"apikey", "apikey-value"}, {"authorization", "Bearer token-value"}]
delete(url, body \\ nil, headers \\ [], opts \\ [])
Simple DELETE request that format the response to a map or retrieve
the error reason as String.t()
.
Examples
iex> Supabase.Fetcher.delete("https://example.com", %{key: "value"})
{:ok, %{"key" => "value"}}
iex> Supabase.Fetcher.delete("https://example.com", %{key: "value"})
{:error, :not_found}
format_response(arg)
get(url)
Simple GET request that format the response to a map or retrieve
the error reason as String.t()
.
Examples
iex> Supabase.Fetcher.get("https://example.com")
{:ok, %{"key" => "value"}}
get(url, body)
get(url, body, headers)
get_full_url(base_url, path)
get_header(response, header)
get_header(resp, header, default)
head(url, body, headers \\ [], opts \\ [])
Simple HEAD request that format the response to a map or
retrieve the error as String.t()
new_connection(method, url, body, headers)
@spec new_connection(atom(), url, body, headers) :: Finch.Request.t() when url: String.t() | URI.t(), body: binary() | nil | {:stream, Enumerable.t()}, headers: [tuple()]
patch(url, body, headers \\ [], opts \\ [])
Simple PATCH request that format the response to a map or
retrieve the error as String.t()
post(url, body \\ nil, headers \\ [], opts \\ [])
Simple POST request that format the response to a map or retrieve
the error reason as String.t()
.
Examples
iex> Supabase.Fetcher.post("https://example.com", %{key: "value"})
{:ok, %{"key" => "value"}}
put(url, body, headers \\ [], opts \\ [])
Simple PUT request that format the response to a map or retrieve
the error reason as String.t()
.
Examples
iex> Supabase.Fetcher.put("https://example.com", %{key: "value"})
{:ok, %{"key" => "value"}}
stream(url, headers \\ [], opts \\ [])
Makes a HTTP request to the desired URL, with default headers and stream back the response. Good to stream large files downlaods.
You can also pass custom Finch
options directly to the underlying Finch.stream/4
function.
Those options can be seen on the Finch documentation.
Examples
iex> {status, stream} = Supabase.Fetcher.stream("https://example.com")
iex> file = File.stream!("path/to/file", [], 4096)
Stream.run Stream.into(stream, file)
upload(method, url, file, headers \\ [])
Upload a binary to the desired URL.
params:
method
::put
or:post
url
: the URL to upload the filefile
: the path to the file to uploadheaders
: list of additional headers to append to the request
Examples
iex> Supabase.Fetcher.upload(:post, "https://example.com", "path/to/file")
{:ok, %{"key" => "value"}}
version()
@spec version() :: String.t()