Listeners in order
An event holds listeners that run one after another, each with its own time limit, in the sandbox or on the native process. They read the data in g.req.eventData.
API Maker
The framework for AI era
Your code
React to API calls with your own listeners, or emit events from any code.
An event runs a list of TypeScript listeners after an API call, or when your code emits it. The caller always gets its response first. Listeners can emit more events, API Maker stops loops for you, and the code that emits an event gets the output of every listener back.
Step through it, slow it down, or open the full canvas.
The response first, then the events. An event can run on every call of an API: generated, schema, custom or system. The caller gets its response first, the event gets that response as its data.
An event can run on every call of an API: generated, schema, custom or system. The caller gets its response first, the event gets that response as its data.
Each listener is TypeScript run in the sandbox, with its own timeout. It reads the data in g.req.eventData: send a receipt, update the stock, call any API.
Any listener can run another event with g.sys.system.emitEvent. Workflows grow step by step, each step in its own listener.
API Maker keeps the chain of events of each call. An event that is already in it is not run again, the caller gets the chain in the error.
Name the listeners to run only those. emitEvent returns the output of each listener. Other systems use the emit-event system API.
An event holds listeners that run one after another, each with its own time limit, in the sandbox or on the native process. They read the data in g.req.eventData.
Attach an event to generated, schema, custom or system APIs: it runs after every call, with the response as its data.
g.sys.system.emitEvent(name, data, listeners) runs an event from any code, all its listeners or only the ones you name.
emitEvent returns the output of each listener that ran, so a custom API can use the result of the workflow it started.
API Maker keeps the chain of events of each call. An event already in the chain is not run again, and the error shows the chain.
The emit-event system API runs an event over REST, with the same data and the same choice of listeners.
The order API answers the shop at once. Then the event order-placed records a notification for the customer, sends the receipt and updates the stock, and a low stock emits stock-low, whose listener orders more from the supplier.
import * as T from 'types';async function main(g: T.IAMGlobal) { const order = g.req.eventData; await g.sys.db.saveSingleOrMultiple({ instance: 'mongodb', database: 'shop', collection: 'notifications', saveData: { customer_id: order.customer_id, text: `Order ${order._id} is paid.` }, });}module.exports = main;import * as T from 'types';async function main(g: T.IAMGlobal) { const order = g.req.body; // Only send-receipt runs : update-stock does not take the stock twice const out = await g.sys.system.emitEvent('order-placed', order, ['send-receipt']); return out.outputArr[0].output; // { listenerName, output } of each listener that ran}module.exports = main;No. The response is written first. Events, WebSocket notifications and logs run after it.
Yes. Pass their names to g.sys.system.emitEvent or to the emit-event system API. A name that does not exist is an error.
With WebSockets: apps register for an API or a custom WebSocket event, and g.sys.system.emitEventWS pushes to them.
Documentation