pub struct Client { /* private fields */ }
Expand description
Main Supabase client for interacting with all services
Implementations§
Source§impl Client
impl Client
Sourcepub fn new(url: &str, key: &str) -> Result<Self>
pub fn new(url: &str, key: &str) -> Result<Self>
Create a new Supabase client with URL and API key
§Arguments
url
- Your Supabase project URL (e.g., “https://your-project.supabase.co”)key
- Your Supabase API key (anon key for client-side operations)
§Example
use supabase::Client;
let client = Client::new("https://your-project.supabase.co", "your-anon-key")?;
Sourcepub fn new_with_service_role(
url: &str,
anon_key: &str,
service_role_key: &str,
) -> Result<Self>
pub fn new_with_service_role( url: &str, anon_key: &str, service_role_key: &str, ) -> Result<Self>
Create a new Supabase client with service role key for admin operations
§Arguments
url
- Your Supabase project URL (e.g., “https://your-project.supabase.co”)anon_key
- Your Supabase anon API key for client-side operationsservice_role_key
- Your Supabase service role key for admin operations
§Example
use supabase::Client;
let client = Client::new_with_service_role(
"https://your-project.supabase.co",
"your-anon-key",
"your-service-role-key"
)?;
Sourcepub fn new_with_config(config: SupabaseConfig) -> Result<Self>
pub fn new_with_config(config: SupabaseConfig) -> Result<Self>
Create a new Supabase client with custom configuration
§Arguments
config
- Custom Supabase configuration
§Example
use supabase::{Client, types::*};
let config = SupabaseConfig {
url: "https://your-project.supabase.co".to_string(),
key: "your-anon-key".to_string(),
service_role_key: None,
http_config: HttpConfig::default(),
auth_config: AuthConfig::default(),
database_config: DatabaseConfig::default(),
storage_config: StorageConfig::default(),
};
let client = Client::new_with_config(config)?;
Sourcepub fn http_client(&self) -> Arc<HttpClient>
pub fn http_client(&self) -> Arc<HttpClient>
Get the HTTP client
Sourcepub fn config(&self) -> Arc<SupabaseConfig>
pub fn config(&self) -> Arc<SupabaseConfig>
Get the client configuration
Sourcepub async fn set_auth(&self, token: &str) -> Result<()>
pub async fn set_auth(&self, token: &str) -> Result<()>
Set a custom authorization header (JWT token)
Sourcepub async fn clear_auth(&self) -> Result<()>
pub async fn clear_auth(&self) -> Result<()>
Clear the current authorization
Sourcepub fn is_authenticated(&self) -> bool
pub fn is_authenticated(&self) -> bool
Check if client is authenticated
Sourcepub async fn current_user(&self) -> Result<Option<User>>
pub async fn current_user(&self) -> Result<Option<User>>
Get current user if authenticated
Sourcepub async fn health_check(&self) -> Result<bool>
pub async fn health_check(&self) -> Result<bool>
Perform a health check on the Supabase instance
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Client
impl !RefUnwindSafe for Client
impl Send for Client
impl Sync for Client
impl Unpin for Client
impl !UnwindSafe for Client
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more