Getting started
Creating first-ever connector
Create a Xomlo.io project in your local folder:
$ yarn create @xomlo/xomlo-app
You will be prompted for a project type and project name. Choose connector
and test-connector
for the name. The builder will create the project into the ./test-connector
folder.
The following code will be generated in ./src/index.ts
:
import { functions } from '@xomlo/xomlo-sdk';
interface Payload {
[key: string]: string;
}
functions.main(async (payload: Payload) => {
// Print current payload
functions.logger.info('Hello from Xomlo connector!');
functions.logger.info('Payload', payload);
// Download test data and save into ./output/data.json
const { body } = await functions.http.get('https://api.thecatapi.com/v1/images/search');
functions.storage.saveOutput('data.json', body);
});
You can test your connector locally by running the following commands in your console:
$ yarn build
$ yarn start
The connector should return into the console:
$ Starting ...
$ debug: ▪ Connector started in develop mode +0ms
$ debug: ▪ Loading envs startsWith XOMLO_PAYLOAD_ from .env file +3ms
$ debug: ▪ Connector status: RUNNING +1ms
$ info: ▪ Hello from Xomlo connector! +2ms
$ info: ┏ Payload +1ms
$ info: ┗ [1] { someEnvVariable: 'someValue' }
$ debug: ▪ HTTP GET request: https://api.thecatapi.com/v1/images/search +7ms
$ debug: ▪ Connector status: FINISHED, elapsedTime: 377ms +368ms
$ debug: ▪ Connector finished +1ms
Code breakdown
All connector logic must be written in the main function. Anything outside won't be run properly in the Xomlo.io runtime environment.
import { functions } from '@xomlo/xomlo-sdk';
functions.main(async () => {
// our code should be here
});
Always use our custom logger instead of console.log()
. You must do this because all logs are sent to our application after the connector is finished in the Xomlo.io runtime.
import { functions } from '@xomlo/xomlo-sdk';
functions.main(async () => {
functions.logger.info('Hello from Xomlo connector!');
});
Last updated
Was this helpful?