Supabase Fetcher

Supabase Logo

The Supabase Fetcher is a versatile HTTP client that serves as an entry point for interacting with Supabase APIs from your Elixir applications. While it's often recommended to use higher-level APIs for specific Supabase services like supabase-storage or the all-in-one package supabase-potion, this SDK provides low-level capabilities for fine-grained control and customization.

Installation

To get started with the Supabase Fetcher Elixir SDK, add it to your Elixir project's dependencies by including it in your mix.exs file:

def deps do
  [
    {:supabase_fetcher, "~> 0.1"}
  ]
end

After adding the dependency, run mix deps.get to fetch and install the SDK.

Overview

This SDK allows you to make HTTP requests to Supabase and handle responses efficiently. It comes with several functions for common HTTP operations, such as GET, POST, PUT, DELETE, and file uploads.

Usage

Streaming Large Files

You can use Supabase.Fetcher.stream/3 to make a GET request to a URL and stream back the response. This function is especially useful for streaming large file downloads. Custom Finch options can also be passed for more control over the request.

{iex> {status, stream} = Supabase.Fetcher.stream("https://example.com")
iex> file = File.stream!("path/to/file", [], 4096)
Stream.run Stream.into(stream, file)

Making HTTP Requests

The SDK provides convenient functions for making common HTTP requests:

These functions format the response to a map or retrieve the error reason as a String.t().

Uploading Files

You can use Supabase.Fetcher.upload/4 to upload a binary file to a URL using either a POST or PUT request. This is useful for file uploads in your applications.

iex> Supabase.Fetcher.upload(:post, "https://example.com/upload", "path/to/file")

Headers and Authentication

The SDK supports adding custom headers to requests. Additionally, you can use Supabase.Fetcher.apply_headers/2 to conveniently set headers for authentication. It automatically includes the API key and, optionally, a token in the headers.

iex> headers = Supabase.Fetcher.apply_headers("apikey-value")
iex> Supabase.Fetcher.get("https://example.com", headers)

Acknowledgements

While the Supabase Fetcher Elixir SDK offers low-level control for making HTTP requests to Supabase, it is part of the broader Supabase ecosystem, which includes higher-level libraries for various Supabase services.

Additional Information

For more details on using this package, refer to the Supabase Fetcher documentation.


With the Supabase Fetcher Elixir SDK, you have the power to interact with Supabase APIs directly from your Elixir applications. Whether you need to stream large files, make custom HTTP requests, or upload files, this SDK has you covered. Enjoy the flexibility and control it offers in integrating with Supabase services! 😄