Terraphim Atomic Client
The terraphim_atomic_client crate provides a comprehensive client implementation for the Atomic Data protocol, enabling seamless integration with Atomic Data servers and resources.
synonyms:: terraphim atomic client checklist:: architecture, api reference, error handling, resource management, wasm compatibility, testing, configuration, best practices
Architecture
Core Components
Atomic Client
The main client struct for Atomic Data operations:
Key Features:
- HTTP client for Atomic Data protocol
- Authentication and authorization
- Resource management
- WASM compatibility
Resource Management
Atomic Data resource handling:
API Reference
Basic Usage
Creating a Client
use AtomicClient;
// Basic client without authentication
let client = new?;
// Client with authentication
let credentials = new?;
let client = with_credentials?;Resource Operations
Get Resource
let resource = client.get_resource.await?;
println!;Create Resource
let mut resource = new;
resource.set_property?;
let created = client.create_resource.await?;Update Resource
let mut resource = client.get_resource.await?;
resource.set_property?;
let updated = client.update_resource.await?;Delete Resource
client.delete_resource.await?;Collection Operations
Get Collection
let collection = client.get_collection.await?;
for resource in collection.resources Add to Collection
client.add_to_collection.await?;Remove from Collection
client.remove_from_collection.await?;Search Operations
Basic Search
let results = client.search.await?;
for result in results Advanced Search
let query = SearchQuery ;
let results = client.search_advanced.await?;Authentication
Basic Authentication
let credentials = new?;
let client = with_credentials?;Token Authentication
let credentials = with_token?;
let client = with_credentials?;Session Management
// Login and get session
let session = client.login.await?;
// Use session for subsequent requests
let client = with_session?;Error Handling
Custom Error Types
Result Types
pub type Result<T> = Result;
// Usage
let resource = client.get_resource.await?;
let results = client.search.await?;Resource Management
Property Operations
let mut resource = new;
// Set string property
resource.set_property?;
// Set number property
resource.set_property?;
// Set boolean property
resource.set_property?;
// Set URL property
resource.set_property?;Collection Operations
// Add to collection
resource.add_to_collection?;
// Remove from collection
resource.remove_from_collection?;WASM Compatibility
WebAssembly Support
The client is designed for WASM deployment:
use *;
pub async Feature Flags
[dependencies.terraphim_atomic_client]
version = "0.1.0"
features = ["wasm-bindgen"]Testing
Unit Tests
Integration Tests
Configuration
Client Configuration
let config = ClientConfig ;
let client = with_config?;Authentication Configuration
let auth_config = AuthConfig ;
let client = with_auth_config?;Best Practices
Resource Management
// Use RAII for client management
let client = new?;
// Handle errors gracefully
match client.get_resource.await Authentication
// Store credentials securely
let credentials = new?;
let client = with_credentials?;
// Use session management for long-running operations
let session = client.login.await?;
let client = with_session?;Error Handling
// Implement retry logic for transient errors
let mut attempts = 0;
let max_attempts = 3;
while attempts < max_attempts Integration Examples
Desktop Application
// In desktop app
let client = new?;
let resources = client.search.await?;
// Update UI with results
update_search_results;Web Application (WASM)
pub async Server Integration
// Server-side Atomic Data integration
let client = with_credentials?;
// Sync local documents with Atomic Data
for document in local_documents Dependencies
Internal Dependencies
terraphim_types: Core type definitionsreqwest: HTTP client implementationserde: Serialization support
External Dependencies
tokio: Async runtimewasm-bindgen: WASM bindings (optional)thiserror: Error handling
Migration Guide
From HTTP Client
- Replace direct HTTP calls with Atomic Client methods
- Use
AtomicResourcefor resource management - Implement proper error handling
- Add authentication if required
From Other Atomic Data Libraries
- Update import statements
- Replace client instantiation
- Update method calls to match API
- Test authentication and error handling