pub struct PocketBase { /* private fields */ }Expand description
A PocketBase client for sending requests to a PocketBase instance.
The Debug implementation for this struct redacts sensitive authentication data
to prevent accidental exposure in logs.
§Example
ⓘ
use std::error::Error;
use pocketbase_rs::PocketBase;
use serde::Deserialize;
#[derive(Deserialize)]
struct Article {
id: String,
title: String,
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
let mut pb = PocketBase::new("http://localhost:8090");
pb.collection("users")
.auth_with_password("YOUR_EMAIL_OR_USERNAME", "YOUR_PASSWORD")
.await?;
let article = pb
.collection("articles")
.get_one::<Article>("record_id")
.call()
.await?;
println!("Article: {:?}", article);
Ok(())
}Implementations§
Source§impl PocketBase
impl PocketBase
Sourcepub fn collection(&mut self, collection_name: &'static str) -> Collection<'_>
pub fn collection(&mut self, collection_name: &'static str) -> Collection<'_>
Creates a new Collection instance for the specified collection name.
This method provides access to operations related to a specific collection in PocketBase.
Most interactions with the PocketBase API are performed through the Collection instance returned
by this method.
§Arguments
collection_name- The name of the collection to interact with, provided as a static string.
§Returns
A Collection instance configured for the specified collection.
§Example
ⓘ
let mut pb = PocketBase::new("http://localhost:8090");
pb.collection("users")
.auth_with_password("YOUR_EMAIL_OR_USERNAME", "YOUR_PASSWORD")
.await?;
let article = pb
.collection("articles")
.get_first_list_item::<Article>()
.filter("language='en'")
.call()
.await?;§Panics
This method will panic if the collection name is empty or contains invalid characters.
Source§impl PocketBase
impl PocketBase
Sourcepub fn new_with_client(base_url: &str, client: Client) -> Self
pub fn new_with_client(base_url: &str, client: Client) -> Self
Creates a new PocketBase client with a custom reqwest client.
§Example
use std::time::Duration;
let reqwest_client = reqwest::Client::builder()
.timeout(Duration::from_secs(60))
.build()
.expect("Failed to build client");
let pb = PocketBase::new_with_client("http://localhost:8090", reqwest_client);§Panics
This method will panic if the provided base_url is not a valid URL.
Sourcepub fn auth_store(&self) -> Option<AuthStore>
pub fn auth_store(&self) -> Option<AuthStore>
Trait Implementations§
Source§impl Clone for PocketBase
impl Clone for PocketBase
Source§fn clone(&self) -> PocketBase
fn clone(&self) -> PocketBase
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for PocketBase
impl !RefUnwindSafe for PocketBase
impl Send for PocketBase
impl Sync for PocketBase
impl Unpin for PocketBase
impl !UnwindSafe for PocketBase
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