Installation
Install the iii SDK via npm:Quick Start
Here’s a simple example that creates a function and exposes it via HTTP:http://localhost:3111/add.
Connection
Initialize the SDK
Connect to the iii engine using the WebSocket URL:Environment Variables
You can configure the connection URL using environment variables:Registering Functions
Basic Function Registration
Register a function that can be invoked by the engine:Function with Description
Provide metadata about your function:Async Operations
All function handlers support async/await:Error Handling
Handle errors gracefully in your functions:Registering Triggers
Triggers determine when and how functions are invoked. iii supports multiple trigger types.- 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
You can invoke functions directly from your code:Fire-and-Forget Invocations
Invoke a function without waiting for the result:Complete Example
Here’s a full example demonstrating multiple features:API Reference
init(url: string)
Initialize the SDK and connect to the iii engine.
Parameters:
url: WebSocket URL of the iii engine (default:ws://localhost:49134)
registerFunction(request, handler)
Register a function with the engine.
Parameters:
request.id: Unique function identifierrequest.description: Optional descriptionhandler: Async function that receives input and returns output
registerTrigger(trigger)
Register a trigger for a function.
Parameters:
trigger.type: Trigger type (http,queue,cron,stream)trigger.function_id: ID of the function to invoketrigger.config: Trigger-specific configuration
invoke(functionId, input, options?)
Invoke a function programmatically.
Parameters:
functionId: ID of the function to invokeinput: Input data for the functionoptions.fireAndForget: Don’t wait for result (optional)
Best Practices
Use meaningful function IDs
Use meaningful function IDs
Use namespaced IDs like
user.create, email.send, data.transform to organize your functions.Handle errors gracefully
Handle errors gracefully
Always handle errors in your functions and return meaningful error messages.
Keep functions focused
Keep functions focused
Each function should do one thing well. Use function invocations to compose complex workflows.
Use TypeScript for type safety
Use TypeScript for type safety
The SDK supports TypeScript for better type checking and IDE support.
Next Steps
Python SDK
Learn about the Python SDK
Rust SDK
Learn about the Rust SDK
HTTP Module
Deep dive into HTTP triggers
Queue Module
Learn about queue-based triggers