pub struct Client { /* private fields */ }Expand description
Client for one Supabase project.
It holds one shared reqwest::Client and one sub-client per enabled feature.
Cloning is cheap: the connection pool is shared.
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(project_url: &str, api_key: &str) -> Result<Self, Error>
pub fn new(project_url: &str, api_key: &str) -> Result<Self, Error>
Creates a client for the project at project_url, for example https://abc.supabase.co/.
The default HTTP client follows up to 10 redirects, only to the same origin.
§Errors
Returns Error::UrlParse or Error::InvalidProjectUrl for a bad URL, and a
sub-client error when a credential is not a valid header value.
Sourcepub fn new_with_client(
project_url: &str,
api_key: &str,
http: Client,
) -> Result<Self, Error>
pub fn new_with_client( project_url: &str, api_key: &str, http: Client, ) -> Result<Self, Error>
Creates a client that reuses the connection pool and policies of http.
The redirect policy of http applies unchanged.
§Errors
Same as Client::new.
Sourcepub fn with_access_token(&self, token: &str) -> Result<Self, Error>
pub fn with_access_token(&self, token: &str) -> Result<Self, Error>
Returns a client that acts as the user who owns token (a JWT from sign-in).
REST, auth, storage, and functions send Authorization: Bearer <token>.
The apikey header keeps the project key. The connection pool is shared.
Without a user token, a legacy JWT key (anon or service_role) is the bearer, as in
supabase-js; a new-format key (sb_publishable_..., sb_secret_...) is sent only as
apikey.
§Errors
Returns a sub-client error when token is not a valid header value.
Sourcepub fn with_storage_url(&self, project_url: &str) -> Result<Self, Error>
pub fn with_storage_url(&self, project_url: &str) -> Result<Self, Error>
Returns a client that sends storage requests to the project at project_url, for
example https://abc.supabase.co/. REST, auth, and functions keep the URL from
Client::new.
Use it when a custom domain proxies REST and auth but not storage.
The storage client keeps its headers, so an access token from
Client::with_access_token stays. Call order does not matter.
§Errors
Returns Error::UrlParse or Error::InvalidProjectUrl for a bad URL.
Sourcepub const fn project_url(&self) -> &Url
pub const fn project_url(&self) -> &Url
Project base URL.
Sourcepub const fn rest(&self) -> &Postgrest
pub const fn rest(&self) -> &Postgrest
REST client for {project}/rest/v1/.
The typed runtime of rp-supabase-client takes this same Postgrest.
Sourcepub fn from(&self, table: &str) -> Builder
pub fn from(&self, table: &str) -> Builder
Starts a query on table. Shortcut for self.rest().from(table).
Sourcepub const fn auth(&self) -> &ApiClient
pub const fn auth(&self) -> &ApiClient
Supabase Auth client for {project}/auth/v1/.
After Client::with_access_token it is authenticated, so get_user,
update_user, and sign_out work.
Sourcepub const fn storage(&self) -> &StorageClient
pub const fn storage(&self) -> &StorageClient
Storage client for {project}/storage/v1/.
Sourcepub const fn functions(&self) -> &FunctionsClient
pub const fn functions(&self) -> &FunctionsClient
Edge Functions client for {project}/functions/v1/.
Sourcepub fn realtime_config(&self) -> SupabaseAuthConfig
pub fn realtime_config(&self) -> SupabaseAuthConfig
Configuration for RealtimeConnection::db_changes, presence, and broadcast.
Realtime signs in on its own, so it uses the project key, not a user token.
Retry defaults for sign-in and token refresh: REALTIME_MAX_RECONNECT_ATTEMPTS
attempts, REALTIME_RECONNECT_INTERVAL apart. The websocket itself does not reconnect.
Change the returned fields to override the retry settings.