Installation
Add the iii SDK to yourCargo.toml:
Quick Start
Here’s a simple example that creates a function and exposes it via HTTP:http://localhost:3111/add.
Connection
Initialize the SDK
Create an iii client instance:Connect to the Engine
Establish a WebSocket connection:Environment Variables
Configure the connection URL using environment variables:Registering Functions
Basic Function Registration
Register a function using a closure:Function with Error Handling
Handle errors explicitly:Structured Input/Output
Use serde for type-safe data handling:Async Operations
Perform async operations within functions:Shared State
Use Arc for shared state across function invocations:Registering Triggers
Register triggers after connecting to the engine.- HTTP
- Queue
- Cron
- Stream
Expose functions as HTTP endpoints:Configuration options:
api_path: The URL path (e.g., ‘add’ →/add)http_method: HTTP method (GET, POST, PUT, DELETE, PATCH)
Invoking Functions
Invoke functions directly from your code:Fire-and-Forget Invocations
Invoke without waiting for a response:Complete Example
Here’s a comprehensive example with multiple functions and triggers:API Reference
III::new(url: &str)
Create a new iii SDK instance.
Parameters:
url: WebSocket URL of the iii engine
async connect(&self)
Connect to the iii engine.
Returns: Result<(), Error>
register_function<F, Fut>(function_id: &str, handler: F)
Register a function with the engine.
Parameters:
function_id: Unique function identifierhandler: Async closure that receivesserde_json::Valueand returnsResult<serde_json::Value, Error>
register_trigger(type: &str, function_id: &str, config: serde_json::Value)
Register a trigger for a function.
Parameters:
type: Trigger type (http,queue,cron,stream)function_id: ID of the function to invokeconfig: Trigger-specific configuration
Result<(), Error>
async invoke(function_id: &str, input: serde_json::Value)
Invoke a function and wait for the result.
Parameters:
function_id: ID of the function to invokeinput: Input data
Result<serde_json::Value, Error>
Best Practices
Use Arc and async-aware locks
Use Arc and async-aware locks
For shared state, use
Arc<RwLock<T>> from tokio to enable concurrent access.Leverage the type system
Leverage the type system
Use serde’s Serialize/Deserialize traits for type-safe input/output handling.
Handle errors with Result
Handle errors with Result
Return
Result types from your functions to handle errors gracefully.Clone Arc references, not data
Clone Arc references, not data
When passing shared state to closures, clone the Arc, not the underlying data.
Use tokio::spawn for background tasks
Use tokio::spawn for background tasks
Spawn background tasks using
tokio::spawn when needed.Next Steps
Node.js SDK
Learn about the Node.js SDK
Python SDK
Learn about the Python SDK
HTTP Module
Deep dive into HTTP triggers
Custom Adapters
Build custom adapters in Rust