Skip to main content
The official Rust SDK for TrailBase provides a type-safe, async client for accessing your TrailBase backend from Rust applications.

Installation

Add trailbase-client to your Cargo.toml:
Cargo.toml

Features

  • ws - Enable WebSocket support for subscriptions (optional)
Cargo.toml

Initialization

Basic Client

Client with Tokens

Authentication

Login

Logout

Current User

Access Tokens

Record API

Define Your Record Types

List Records

Read a Record

Create a Record

Update a Record

Delete a Record

Filtering

Available Comparison Operators

Real-time Subscriptions

Subscribe to Record Changes

Subscribe to All Records

WebSocket Subscriptions

With the ws feature enabled:

Error Handling

Type Definitions

User

Tokens

ListResponse

Pagination

DbEvent

RecordId Trait

The RecordId trait allows using different types as record identifiers:

Best Practices

Use the #[derive(Serialize, Deserialize)] macros on your record types for seamless serialization.
Store tokens securely and never commit them to version control. Consider using environment variables or secure credential storage.
The client automatically refreshes auth tokens before they expire. Manual refresh is rarely needed.

Example Application