Skip to main content

Installation

Add the iii SDK to your Cargo.toml:

Quick Start

Here’s a simple example that creates a function and exposes it via HTTP:
Your function is now live at 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.
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)
Dynamic routes:

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
Returns: SDK instance

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 identifier
  • handler: Async closure that receives serde_json::Value and returns Result<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 invoke
  • config: Trigger-specific configuration
Returns: 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 invoke
  • input: Input data
Returns: Result<serde_json::Value, Error>

Best Practices

For shared state, use Arc<RwLock<T>> from tokio to enable concurrent access.
Use serde’s Serialize/Deserialize traits for type-safe input/output handling.
Return Result types from your functions to handle errors gracefully.
When passing shared state to closures, clone the Arc, not the underlying data.
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