🦀 DynaRust Client (Official Rust SDK)
The official, asynchronous, and type-safe Rust client for DynaRust — the distributed, horizontally scalable key-value store.
This library provides a seamless wrapper around the DynaRust REST API, allowing you to interact with your cluster using strongly-typed Rust structs, automatic JSON deserialization, and async/await syntax 🔄.
✨ Key Features
- 🚀 Async by Default: Built on top of
tokioandreqwestfor non-blocking, high-performance I/O. - 📦 Strongly Typed: Uses standard
serdetraits. Fetch data from DynaRust and deserialize it directly into your own custom Rust structs! - 🔒 Built-in Authentication: Easily manage and attach JWT tokens for secure
PUTandDELETEoperations. - 🛡️ Error Handling: Meaningful, standardized
DynaErrortypes (e.g.,NotFound,Unauthorized) so you don't have to parse raw HTTP status codes.
📦 Installation
Add the client to your project using Cargo:
Basic usage
use ;
use ;
// 1️⃣ Define your custom data structure
async
Real-Time Subscriptions (SSE)
use StreamExt; // Required for stream iteration
async
📡 API Reference DynaClient::new(base_url: &str)
Creates a new client instance. You can point this to any active node in your DynaRust cluster.
client.auth(user: &str, secret: &str)
Registers or logs in a user. If successful, automatically securely stores the returned JWT token inside the DynaClient instance for future PUT and DELETE requests.
client.set_token(token: String)
Manually attach a JWT authentication token to the client (useful if you handle authentication elsewhere).
client.get_value::(table: &str, key: &str)
Retrieves the latest version of a key from the specified table. Does not require authentication.
Returns: Result<VersionedValue, DynaError>
client.put_value(table: &str, key: &str, value: &T)
Creates or updates a key. Requires the client to be authenticated as the record's owner.
Returns: Result<VersionedValue, DynaError>
client.delete_value(table: &str, key: &str)
Deletes a key from the table. Requires the client to be authenticated as the record's owner.
Returns: Result<(), DynaError>
client.subscribe::(table: &str, key: &str)
Opens a Server-Sent Events (SSE) connection to the cluster.
Returns: An asynchronous Stream that yields Result<VersionedValue, DynaError> whenever the key is modified.
🆘 Troubleshooting Error: Request failed: error sending request... connection refused Make sure your DynaRust node is running and accessible at the URL provided to DynaClient::new(). If running in Docker, ensure your ports are mapped correctly.
Error: Unexpected status 401: Unauthorized access You attempted a write/delete operation without authenticating. Make sure to call client.auth() or client.set_token() before making the request.
Error: trait bound is not satisfied Ensure the struct you are passing to generic methods has #[derive(Serialize, Deserialize)] attached to it.
🤝 Contributing
Pull requests are welcome! If you find a bug or want to help expand this client, feel free to open an issue or submit a PR on the main repository.