Health & Files
import { Aside } from ‘@astrojs/starlight/components’;
checkHealth()
Section titled “checkHealth()”Probe the PocketBase health endpoint to verify the server is reachable and running.
PBResponse checkHealth();Does not require a collection to be set. Returns a PBResponse.
PocketBase endpoint: GET /api/health
PBResponse health = pb.checkHealth();
if (!health.ok) { Serial.println("PocketBase unreachable (status " + String(health.statusCode) + ")"); // statusCode == 0 means connection failed entirely while (true) delay(1000); // halt}
Serial.println("Server healthy: " + health.body);// Body: {"code":200,"message":"API is healthy."}Typical use — call checkHealth() once at device startup, after WiFi connects, before attempting any record or auth operations:
void setup() { // ... WiFi connect ...
PBResponse health = pb.checkHealth(); if (!health.ok) { Serial.println("Cannot reach PocketBase, halting"); while (true) delay(1000); }
// Proceed with app logic}getFileUrl()
Section titled “getFileUrl()”Build the full URL for a file attached to a record. No HTTP request is made — this is a pure string-construction helper.
String getFileUrl( const char* recordId, const char* filename, const char* thumb = nullptr);| Parameter | Type | Description |
|---|---|---|
recordId | const char* | ID of the record that owns the file. |
filename | const char* | Exact filename as stored in the record field (e.g. "photo_xyz.jpg"). |
thumb | const char* | Optional thumbnail size string, e.g. "100x100" or "0x50". Pass nullptr for the original file. |
The returned URL follows the PocketBase file path convention:
{baseUrl}/api/files/{collection}/{recordId}/{filename}With a thumb parameter:
{baseUrl}/api/files/{collection}/{recordId}/{filename}?thumb={thumb}// Original fileString url = pb.getFileUrl("RECORD_ID", "photo.jpg");// https://my-pb.com/api/files/avatars/RECORD_ID/photo.jpg
// ThumbnailString thumb = pb.getFileUrl("RECORD_ID", "photo.jpg", "100x100");// https://my-pb.com/api/files/avatars/RECORD_ID/photo.jpg?thumb=100x100
// Constrained height, auto widthString tall = pb.getFileUrl("RECORD_ID", "banner.png", "0x200");// https://my-pb.com/api/files/avatars/RECORD_ID/banner.png?thumb=0x200The active collection set via .collection() is used as the collection segment of the URL.