Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ end

Individual product client documentation:

- [PostgREST](https://github.com/supabase-community/postgres-ex)
- [PostgREST](https://github.com/supabase-community/postgrest-ex)
- [Storage](https://github.com/supabase-community/storage-ex)
- [Auth](https://github.com/supabase-community/auth-ex)
- [Functions](https://github.com/supabase-community/functions-ex)
- [Realtime](https://github.com/supabase-community/realtime-ex)

### Clients

A `Supabase.Client` holds general information about Supabase, that can be used to intereact with any of the children integrations, for example: `Supabase.Storage` or `Supabase.UI`.
A `Supabase.Client` holds general information about Supabase that can be used to interact with any of the children integrations, for example: `Supabase.Storage` or `Supabase.UI`.

### Usage

Expand All @@ -35,7 +35,7 @@ There are two ways to create a `Supabase.Client`:

#### One off clients

One off clients are clients that are created and managed by your application. They are useful for quick interactions with the Supabase API.
One off clients are created and managed by your application. They are useful for quick interactions with the Supabase API.

```elixir
iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>")
Expand All @@ -53,29 +53,29 @@ iex> Supabase.init_client("https://<supabase-url>", "<supabase-api-key>",
iex> {:ok, %Supabase.Client{}}
```

Initialized clients are elixir structs without any managed state.
Initialized clients are Elixir structs without any managed state.

You can also implement the `Supabase.Client.Behaviour` callbacks to cntralize client init logic.
You can also implement the `Supabase.Client.Behaviour` callbacks to centralize client initialisation logic.

#### Self managed clients

Self managed clients are clients that are created and managed by a separate process on your application. They are useful for long running applications that need to interact with the Supabase API.
Self managed clients are created and managed by a separate process in your application. They are useful for long running applications that need to interact with the Supabase API.

If you don't have experience with processes or is a Elixir begginner, you should take a deep look into the Elixir official getting started section about processes, concurrency and distribution before to proceed.
If you don't have experience with processes or are new to Elixir, you should read the getting started section of the official Elixir documentation - specifically about processes, concurrency and distribution before proceeding.
- [Processes](https://hexdocs.pm/elixir/processes.html)
- [Agent getting started](https://hexdocs.pm/elixir/agents.html)
- [GenServer getting started](https://hexdocs.pm/elixir/genservers.html)
- [Supervison trees getting started](https://hexdocs.pm/elixir/supervisor-and-application.html)
- [Supervision trees getting started](https://hexdocs.pm/elixir/supervisor-and-application.html)

So, to define a self managed client, you need to define a module that will hold the client state and the client process as an [Agent](https://hexdocs.pm/elixir/Agent.html).
To define a self managed client, create a module that will hold the client state and the client process as an [Agent](https://hexdocs.pm/elixir/Agent.html).

```elixir
defmodule MyApp.Supabase.Client do
use Supabase.Client, otp_app: :my_app
end
```

For that to work, you also need to configure the client in your app configuration, it can be a compile-time config on `config.exs` or a runtime config in `runtime.exs`:
For that to work, you will also need to configure the client in your application's configuration. This can be configured as a compile-time entry in `config.exs` or as a runtime entry in `runtime.exs`:

```elixir
import Config
Expand All @@ -91,7 +91,7 @@ config :my_app, MyApp.Supabase.Client,
global: [headers: %{"custom-header" => "custom-value"}]
```

Then, you can start the client process in your application supervision tree, generally in your `application.ex` module:
Then you can start the client process in your application supervision tree, generally in a `application.ex` module:

```elixir
defmodule MyApp.Application do
Expand Down
Loading