io.interop API

The Interop API for RPC-style methods and real-time data streams.

Methods

register()

Register an interop method that can be invoked by other apps.

io.interop.register(name: string, handler: (args, caller) => any): Promise<void>
ParameterTypeDescription
namerequiredstringMethod name.
handlerrequiredfunctionHandler receiving args object and caller info. Can return a value or Promise.
Example
await io.interop.register("GetPrice", ({ symbol }) => ({
  symbol,
  price: 142.50,
  timestamp: Date.now(),
}));

unregister()

io.interop.unregister(name: string): void

invoke()

Invoke a registered method on a remote app.

io.interop.invoke(name: string, args?: object, target?: "best" | "all" | InstanceTarget): Promise<InvocationResult>
ParameterTypeDescription
namerequiredstringMethod name to invoke.
argsobjectArguments passed to the handler.
targetstring | object"best" (default), "all", or a specific instance target.
Example
const result = await io.interop.invoke("GetPrice", { symbol: "AAPL" });
console.log(result.returned); // { symbol: "AAPL", price: 142.50, ... }

methods()

List all registered methods across the platform.

io.interop.methods(): MethodDefinition[]

servers()

Get all servers that have registered a specific method.

io.interop.servers(methodName: string): Instance[]

Streams

createStream()

Create a data stream that clients can subscribe to.

io.interop.createStream(methodDef: string | object, options?: StreamOptions): Promise<Stream>
Example
const stream = await io.interop.createStream("MarketData.Prices", {
  subscriptionRequestHandler: (req) => req.acceptOnBranch(req.arguments.symbol),
});
// Push data to a branch
stream.push({ price: 142.50 }, "AAPL");

subscribe() (Stream)

Subscribe to a stream published by another app.

io.interop.subscribe(name: string, options: { arguments?, onData, onClosed }): Promise<Subscription>
Example
const sub = await io.interop.subscribe("MarketData.Prices", {
  arguments: { symbol: "AAPL" },
  onData: (data) => console.log(data.data),
  onClosed: () => console.log("Stream closed"),
});
// Later: sub.close();